Skip to content

Commit 5904633

Browse files
committed
Simplify logic in "round"
1 parent b82ad80 commit 5904633

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/gfloat/round.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ def round_float(
6363

6464
else:
6565
# Extract significand (mantissa) and exponent
66-
fsignificand, expval = np.frexp(vpos)
67-
assert fsignificand >= 0.5 and fsignificand < 1.0
68-
# Bring significand into range [1.0, 2.0)
69-
fsignificand *= 2
70-
expval -= 1
66+
expval = int(np.floor(np.log2(vpos)))
67+
fsignificand = vpos * 2.0**-expval
68+
69+
assert fsignificand >= 1.0 and fsignificand < 2.0
7170

7271
# Effective precision, accounting for right shift for subnormal values
7372
biased_exp = expval + bias

0 commit comments

Comments
 (0)