Skip to content

Commit 247f141

Browse files
committed
Better explanation
1 parent 2d01e39 commit 247f141

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

docs/source/05-stochastic-rounding.ipynb

Lines changed: 50 additions & 40 deletions
Large diffs are not rendered by default.

src/gfloat/round_ndarray.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ def round_ndarray(
9191
## RTNE delta to srbits
9292
d = delta * 2.0**srnumbits
9393
floord = np.floor(d).astype(np.int64)
94-
d = floord + ((d - floord > 0.5) | ((d - floord == 0.5) & _isodd(floord)))
94+
dd = d - floord
95+
drnd = floord + (dd > 0.5) + ((dd == 0.5) & ~_isodd(floord))
9596

96-
should_round_away = d > srbits
97+
should_round_away = drnd > srbits
9798
case RoundMode.StochasticFast:
9899
assert srbits is not None
99100
should_round_away = delta > (2 * srbits + 1) * 2.0 ** -(1 + srnumbits)

0 commit comments

Comments
 (0)