Skip to content

Commit 65ece14

Browse files
committed
Fix for K=64
1 parent de588fe commit 65ece14

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/gfloat/round.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,15 @@ def round_float(
6262
# Extract exponent
6363
expval = int(np.floor(np.log2(vpos)))
6464

65-
assert expval > -1024 + p # not yet tested for float64 near-subnormals
66-
6765
# Effective precision, accounting for right shift for subnormal values
6866
if fi.has_subnormals:
6967
expval = max(expval, 1 - bias)
7068

7169
# Lift to "integer * 2^e"
7270
expval = expval - p + 1
7371

74-
fsignificand = vpos * 2.0**-expval
72+
# use ldexp instead of vpos*2**-expval to avoid overflow
73+
fsignificand = math.ldexp(vpos, -expval)
7574

7675
# Round
7776
isignificand = math.floor(fsignificand)

0 commit comments

Comments
 (0)