Skip to content

Commit 8f4ae20

Browse files
committed
Rename rounding modes
1 parent ec08144 commit 8f4ae20

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/gfloat/round.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def round_float(
114114
)
115115

116116
should_round_away = d > srbits
117-
case RoundMode.StochasticNearly:
117+
case RoundMode.StochasticFastest:
118118
should_round_away = delta > (0.5 + srbits) * 2.0**-srnumbits
119119
case RoundMode.StochasticFast:
120120
should_round_away = delta > srbits * 2.0**-srnumbits

src/gfloat/round_ndarray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ def round_ndarray(
9595

9696
should_round_away = d > srbits
9797
case RoundMode.StochasticFast:
98-
assert srbits is not None
99-
should_round_away = delta > srbits * 2.0**-srnumbits
100-
case RoundMode.StochasticNearly:
10198
assert srbits is not None
10299
should_round_away = delta > (2 * srbits + 1) * 2.0 ** -(1 + srnumbits)
100+
case RoundMode.StochasticFastest:
101+
assert srbits is not None
102+
should_round_away = delta > srbits * 2.0**-srnumbits
103103

104104
isignificand = np.where(should_round_away, isignificand + 1, isignificand)
105105

src/gfloat/types.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ class RoundMode(Enum):
1717
TiesToEven = 4 #: Round to nearest, ties to even
1818
TiesToAway = 5 #: Round to nearest, ties away from zero
1919
Stochastic = 6 #: Stochastic rounding
20-
StochasticFast = 7 #: Stochastic rounding - faster, but biased.
21-
StochasticNearly = 8 #: Stochastic rounding - incorrect, see [Note 1].
20+
StochasticFast = 7 #: Stochastic rounding - faster, but biased, see [Note 1].
21+
StochasticFastest = 8 #: Stochastic rounding - incorrect, see [Note 1].
2222

2323

2424
# [Note 1]:
25-
# StochasticNearly implements a stochastic rounding scheme that is unbiased in
25+
# StochasticFast implements a stochastic rounding scheme that is unbiased in
2626
# infinite precision, but biased when the quantity to be rounded is computed to
2727
# a finite precision.
28+
#
29+
# StochasticFastest implements a stochastic rounding scheme that is biased
30+
# (the rounded value is on average farther from zero than the true value).
31+
#
32+
# With a lot of SRbits (say 8 or more), these biases are negligible, and there
33+
# may be some efficiency advantage in using StochasticFast or StochasticFastest.
2834

2935

3036
class FloatClass(Enum):

0 commit comments

Comments
 (0)