Skip to content

Commit 558db88

Browse files
committed
FIX: Consider rounded error adjusted in default round
1 parent 0bfc05d commit 558db88

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

labfis/uncertainty.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ def __round__(self, p: int = 0) -> labfloat:
232232
u = Decimal(self._uncertainty)
233233
m = Decimal(self._mean)
234234

235-
p += -u.adjusted() * (not p)
235+
r = p - u.adjusted() * (not p)
236236

237-
u = round(u, p)
238-
u += Decimal("1e{}".format(-p)) * (not u)
237+
u = round(u, r)
239238

240-
m = round(m, p)
239+
r = p - u.adjusted() * (not p)
240+
241+
u += Decimal("1e{}".format(-r)) * (not u)
242+
243+
m = round(m, r)
241244

242245
setcontext(current_contex)
243246

0 commit comments

Comments
 (0)