@@ -50,6 +50,8 @@ def rnd_array(
5050@pytest .mark .parametrize ("round_float" , (rnd_scalar , rnd_array ))
5151def test_round_p3109 (round_float : Callable ) -> None :
5252 fi = format_info_p3109 (8 , 4 )
53+
54+ assert fi .max == 224.0
5355 assert round_float (fi , 0.0068359375 ) == 0.0068359375
5456 assert round_float (fi , 0.0029296875 ) == 0.0029296875
5557 assert round_float (fi , 0.0078125 ) == 0.0078125
@@ -73,6 +75,47 @@ def test_round_p3109(round_float: Callable) -> None:
7375
7476 assert round_float (fi , 232.1 ) == np .inf
7577
78+ def _isodd (v : int ) -> bool :
79+ return v & 0x1 == 1
80+
81+ assert round_float (fi , 224.1 , RoundMode .ToOdd ) == np .inf
82+
83+ fi_binary4p2se = format_info_p3109 (4 , 2 , Signedness .Signed , Domain .Extended )
84+ # Top three values are 1.0, 1.5, 2.0; even, odd, even
85+ assert fi_binary4p2se .max == 2.0
86+ assert not _isodd (fi_binary4p2se .code_of_max )
87+
88+ assert round_float (fi_binary4p2se , 1.0 , RoundMode .ToOdd ) == 1.0
89+ assert round_float (fi_binary4p2se , 1.01 , RoundMode .ToOdd ) == 1.5
90+ assert round_float (fi_binary4p2se , 1.5 , RoundMode .ToOdd ) == 1.5
91+ assert round_float (fi_binary4p2se , 1.99 , RoundMode .ToOdd ) == 1.5
92+ assert round_float (fi_binary4p2se , 2.0 , RoundMode .ToOdd ) == 2.0 # max
93+ assert round_float (fi_binary4p2se , 2.01 , RoundMode .ToOdd ) == np .inf
94+
95+ fi_binary4p2ue = format_info_p3109 (4 , 2 , Signedness .Unsigned , Domain .Extended )
96+ # Top two values are 4.0, 6.0, then would be 8.0; even, odd, even
97+ assert fi_binary4p2ue .max == 6.0
98+ assert _isodd (fi_binary4p2ue .code_of_max )
99+
100+ assert round_float (fi_binary4p2ue , 4.00 , RoundMode .ToOdd ) == 4.0
101+ assert round_float (fi_binary4p2ue , 4.01 , RoundMode .ToOdd ) == 6.0
102+ assert round_float (fi_binary4p2ue , 6.0 , RoundMode .ToOdd ) == 6.0 # max
103+ assert round_float (fi_binary4p2ue , 6.01 , RoundMode .ToOdd ) == 6.0
104+ assert round_float (fi_binary4p2ue , 7.99 , RoundMode .ToOdd ) == 6.0
105+ assert round_float (fi_binary4p2ue , 8.0 , RoundMode .ToOdd ) == np .inf # max + 1 ulp
106+
107+ fi_binary4p2uf = format_info_p3109 (4 , 2 , Signedness .Unsigned , Domain .Finite )
108+ # top 3 are 4.0, 6.0, 8.0; even, odd, even; sat must be true
109+ assert fi_binary4p2uf .max == 8.0
110+ assert not _isodd (fi_binary4p2uf .code_of_max )
111+
112+ assert round_float (fi_binary4p2uf , 3.99 , RoundMode .ToOdd , True ) == 3.0
113+ assert round_float (fi_binary4p2uf , 4.01 , RoundMode .ToOdd , True ) == 6.0
114+ assert round_float (fi_binary4p2uf , 6.01 , RoundMode .ToOdd , True ) == 6.0
115+ assert round_float (fi_binary4p2uf , 7.99 , RoundMode .ToOdd , True ) == 6.0
116+ assert round_float (fi_binary4p2uf , 8.0 , RoundMode .ToOdd , True ) == 8.0
117+ assert round_float (fi_binary4p2uf , 8.01 , RoundMode .ToOdd , True ) == 8.0
118+
76119
77120p4min = 2 ** - 10 # smallest subnormal in 8p4
78121
@@ -171,6 +214,26 @@ def test_round_p3109(round_float: Callable) -> None:
171214 (- 58.0 , - 60.0 ),
172215 ),
173216 ),
217+ (
218+ RoundMode .ToOdd ,
219+ (
220+ (p4min , p4min ),
221+ (p4min / 4 , p4min ),
222+ (p4min / 2 , p4min ),
223+ (- p4min , - p4min ),
224+ (- p4min / 4 , - p4min ),
225+ (- p4min / 2 , - p4min ),
226+ (64.0 , 64.0 ),
227+ (63.0 , 60.0 ),
228+ (62.0 , 60.0 ),
229+ (61.0 , 60.0 ),
230+ (- 64.0 , - 64.0 ),
231+ (- 63.0 , - 60.0 ),
232+ (- 62.0 , - 60.0 ),
233+ (- 61.0 , - 60.0 ),
234+ (- 58.0 , - 60.0 ),
235+ ),
236+ ),
174237 ),
175238)
176239@pytest .mark .parametrize ("round_float" , (rnd_scalar , rnd_array ))
@@ -320,6 +383,32 @@ def test_round_p3109b(round_float: Callable, mode: RoundMode, vals: list) -> Non
320383 (- np .inf , - np .inf ),
321384 ),
322385 ),
386+ (
387+ (RoundMode .ToOdd , True ),
388+ (
389+ (p4max , p4max ),
390+ (p4maxhalfup , p4max ),
391+ (p4maxup , p4max ),
392+ (np .inf , p4max ),
393+ (- p4max , - p4max ),
394+ (- p4maxhalfup , - p4max ),
395+ (- p4maxup , - p4max ),
396+ (- np .inf , - p4max ),
397+ ),
398+ ),
399+ (
400+ (RoundMode .ToOdd , False ),
401+ (
402+ (p4max , p4max ),
403+ (p4maxhalfup , np .inf ),
404+ (p4maxup , np .inf ),
405+ (np .inf , np .inf ),
406+ (- p4max , - p4max ),
407+ (- p4maxhalfup , - np .inf ),
408+ (- p4maxup , - np .inf ),
409+ (- np .inf , - np .inf ),
410+ ),
411+ ),
323412 ),
324413 ids = lambda x : f"{ str (x [0 ])} -{ 'Sat' if x [1 ] else 'Inf' } " if len (x ) == 2 else None ,
325414)
0 commit comments