Skip to content

Commit bc9deeb

Browse files
committed
Add comparison to "SRFast"
1 parent ca391b8 commit bc9deeb

File tree

3 files changed

+78
-25
lines changed

3 files changed

+78
-25
lines changed

docs/source/05-stochastic-rounding.ipynb

Lines changed: 75 additions & 25 deletions
Large diffs are not rendered by default.

src/gfloat/round.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def round_float(
106106
should_round_away = delta > 0.5 or (delta == 0.5 and code_is_odd)
107107
if rnd == RoundMode.Stochastic:
108108
should_round_away = delta > (0.5 + srbits) * 2.0**-srnumbits
109+
if rnd == RoundMode.StochasticFast:
110+
should_round_away = delta > srbits * 2.0**-srnumbits
109111

110112
if should_round_away:
111113
# This may increase isignificand to 2**p,

src/gfloat/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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 - possibly faster, but biased.
2021

2122

2223
class FloatClass(Enum):

0 commit comments

Comments
 (0)