Skip to content

Commit af53ab9

Browse files
committed
Simplify p=1 rounding
1 parent cddcb4c commit af53ab9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/gfloat/round.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,10 @@ def round_float(
108108
should_round_away = delta > (0.5 + srbits) * 2.0**-srnumbits
109109

110110
if should_round_away:
111-
if fi.precision > 1:
112-
isignificand += 1
113-
else:
114-
# Increment isignificand if zero, else increment exponent
115-
if isignificand == 0:
116-
isignificand = 1
117-
else:
118-
assert isignificand == 1
119-
expval += 1
111+
# This may increase isignificand to 2**p,
112+
# which would require special casing in encode,
113+
# but not here, where we reconstruct a rounded value.
114+
isignificand += 1
120115

121116
# Reconstruct rounded result to float
122117
result = isignificand * (2.0**expval)

0 commit comments

Comments
 (0)