@@ -49,7 +49,7 @@ def round_float(
49
49
p = fi .precision
50
50
bias = fi .expBias
51
51
52
- if rnd == RoundMode .Stochastic :
52
+ if rnd in ( RoundMode .Stochastic , RoundMode . StochasticFast ) :
53
53
if srbits >= 2 ** srnumbits :
54
54
raise ValueError (f"srnumbits={ srnumbits } >= 2**srnumbits={ 2 ** srnumbits } " )
55
55
@@ -94,20 +94,21 @@ def round_float(
94
94
else (isignificand != 0 and _isodd (expval + bias ))
95
95
)
96
96
97
- if rnd == RoundMode .TowardZero :
98
- should_round_away = False
99
- if rnd == RoundMode .TowardPositive :
100
- should_round_away = not sign and delta > 0
101
- if rnd == RoundMode .TowardNegative :
102
- should_round_away = sign and delta > 0
103
- if rnd == RoundMode .TiesToAway :
104
- should_round_away = delta >= 0.5
105
- if rnd == RoundMode .TiesToEven :
106
- should_round_away = delta > 0.5 or (delta == 0.5 and code_is_odd )
107
- if rnd == RoundMode .Stochastic :
108
- should_round_away = delta > (0.5 + srbits ) * 2.0 ** - srnumbits
109
- if rnd == RoundMode .StochasticFast :
110
- should_round_away = delta > srbits * 2.0 ** - srnumbits
97
+ match rnd :
98
+ case RoundMode .TowardZero :
99
+ should_round_away = False
100
+ case RoundMode .TowardPositive :
101
+ should_round_away = not sign and delta > 0
102
+ case RoundMode .TowardNegative :
103
+ should_round_away = sign and delta > 0
104
+ case RoundMode .TiesToAway :
105
+ should_round_away = delta >= 0.5
106
+ case RoundMode .TiesToEven :
107
+ should_round_away = delta > 0.5 or (delta == 0.5 and code_is_odd )
108
+ case RoundMode .Stochastic :
109
+ should_round_away = delta > (0.5 + srbits ) * 2.0 ** - srnumbits
110
+ case RoundMode .StochasticFast :
111
+ should_round_away = delta > srbits * 2.0 ** - srnumbits
111
112
112
113
if should_round_away :
113
114
# This may increase isignificand to 2**p,
0 commit comments