Skip to content

Commit ec08144

Browse files
committed
Fix test for RTNE
1 parent b2c8e40 commit ec08144

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/gfloat/round.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def round_float(
106106
case RoundMode.TiesToEven:
107107
should_round_away = delta > 0.5 or (delta == 0.5 and code_is_odd)
108108
case RoundMode.Stochastic:
109+
## RTNE delta to srbits
110+
d = delta * 2.0**srnumbits
111+
floord = np.floor(d).astype(np.int64)
112+
d = floord + (
113+
(d - floord > 0.5) or ((d - floord == 0.5) and _isodd(floord))
114+
)
115+
116+
should_round_away = d > srbits
117+
case RoundMode.StochasticNearly:
109118
should_round_away = delta > (0.5 + srbits) * 2.0**-srnumbits
110119
case RoundMode.StochasticFast:
111120
should_round_away = delta > srbits * 2.0**-srnumbits

test/test_round.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_round_roundtrip(round_float: Callable, fi: FormatInfo) -> None:
494494
"v, srnumbits, expected_up",
495495
(
496496
(259, 3, 0.0 / 8),
497-
(259, 5, 1.0 / 32),
497+
(259, 5, 2.0 / 32),
498498
(277, 3, 3.0 / 8),
499499
(288, 3, 0.5),
500500
(311, 3, 7.0 / 8),

0 commit comments

Comments
 (0)