File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -62,22 +62,19 @@ def round_float(
62
62
result = 0.0
63
63
64
64
else :
65
- # Extract significand (mantissa) and exponent
65
+ # Extract exponent
66
66
expval = int (np .floor (np .log2 (vpos )))
67
- fsignificand = vpos * 2.0 ** - expval
68
67
69
- assert fsignificand >= 1.0 and fsignificand < 2.0
68
+ assert expval > - 1024 + p # not yet tested for float64 near-subnormals
70
69
71
70
# Effective precision, accounting for right shift for subnormal values
72
- biased_exp = expval + bias
73
71
if fi .has_subnormals :
74
- effective_precision = t + min (biased_exp - 1 , 0 )
75
- else :
76
- effective_precision = t
72
+ expval = max (expval , 1 - bias )
77
73
78
74
# Lift to "integer * 2^e"
79
- fsignificand *= 2.0 ** effective_precision
80
- expval -= effective_precision
75
+ expval -= t
76
+
77
+ fsignificand = vpos * 2.0 ** - expval
81
78
82
79
# Round
83
80
isignificand = math .floor (fsignificand )
@@ -101,8 +98,9 @@ def round_float(
101
98
else :
102
99
# All other modes tie to even
103
100
if fi .precision == 1 :
104
- # No significand bits
101
+ # No bits in significand
105
102
assert (isignificand == 1 ) or (isignificand == 0 )
103
+ biased_exp = expval + bias
106
104
if _isodd (biased_exp ):
107
105
expval += 1
108
106
else :
You can’t perform that action at this time.
0 commit comments