@@ -224,6 +224,10 @@ def test_numbers(self):
224224 [- 1 << 63 , (1 << 63 )- 1 , 0 ]),
225225 (['l' ], SIGNED_INT64_BE , '>qqq' ,
226226 [- 1 << 63 , (1 << 63 )- 1 , 0 ]),
227+ (['e' ], IEEE_754_FLOAT16_LE , '<eeee' ,
228+ [1.0 , float ('inf' ), float ('-inf' ), - 0.0 ]),
229+ (['e' ], IEEE_754_FLOAT16_BE , '>eeee' ,
230+ [1.0 , float ('inf' ), float ('-inf' ), - 0.0 ]),
227231 (['f' ], IEEE_754_FLOAT_LE , '<ffff' ,
228232 [16711938.0 , float ('inf' ), float ('-inf' ), - 0.0 ]),
229233 (['f' ], IEEE_754_FLOAT_BE , '>ffff' ,
@@ -254,6 +258,16 @@ def test_numbers(self):
254258 self .assertEqual (a , b ,
255259 msg = "{0!r} != {1!r}; testcase={2!r}" .format (a , b , testcase ))
256260
261+ def test_float16_endianness (self ):
262+ # gh-154568: array_reconstructor() slow-path decoder for
263+ # IEEE_754_FLOAT16_LE ignored the encoding.
264+ le_bytes = struct .pack ('<e' , 1.5 )
265+ be_bytes = struct .pack ('>e' , 1.5 )
266+ b_le = array_reconstructor (array .array , 'd' , IEEE_754_FLOAT16_LE , le_bytes )
267+ b_be = array_reconstructor (array .array , 'd' , IEEE_754_FLOAT16_BE , be_bytes )
268+ self .assertEqual (b_le .tolist (), [1.5 ])
269+ self .assertEqual (b_be .tolist (), [1.5 ])
270+
257271 def test_unicode (self ):
258272 teststr = "Bonne Journ\xe9 e \U0002030a \U00020347 "
259273 testcases = (
0 commit comments