Commit 32009f2
committed
[PATCH] Fix float16 pack/unpack on big-endian systems
PyFloat_Pack2() and PyFloat_Unpack2() (and their underscore-prefixed
predecessors) take an 'le' parameter where 0 means big-endian and 1
means little-endian storage. The code was passing PY_BIG_ENDIAN which
evaluates to 0 on little-endian and 1 on big-endian - exactly the
opposite of what is needed, since the bitstream always operates in
big-endian (MSB-first) byte order.
On little-endian systems PY_BIG_ENDIAN=0 happened to produce the correct
result (big-endian storage), masking the bug. On big-endian systems
PY_BIG_ENDIAN=1 caused little-endian storage, resulting in byte-swapped
float16 values.
Replace PY_BIG_ENDIAN with the literal 0 (= big-endian) to get
consistent behavior across all architectures.
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>1 parent 99f8088 commit 32009f2
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
| 437 | + | |
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
| 450 | + | |
451 | 451 | | |
452 | | - | |
| 452 | + | |
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
| |||
0 commit comments