|
11 | 11 | #include "pycore_bytesobject.h" // _PyBytes_Repeat |
12 | 12 | #include "pycore_call.h" // _PyObject_CallMethod() |
13 | 13 | #include "pycore_ceval.h" // _PyEval_GetBuiltin() |
| 14 | +#include "pycore_floatobject.h" // _PY_FLOAT_BIG_ENDIAN |
14 | 15 | #include "pycore_modsupport.h" // _PyArg_NoKeywords() |
15 | 16 | #include "pycore_moduleobject.h" // _PyModule_GetState() |
16 | 17 | #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() |
@@ -91,9 +92,6 @@ enum machine_format_code { |
91 | 92 | * instead of using the memory content of the array directly. In that |
92 | 93 | * case, the array_reconstructor mechanism is bypassed completely, and |
93 | 94 | * the standard array constructor is used instead. |
94 | | - * |
95 | | - * This is will most likely occur when the machine doesn't use IEEE |
96 | | - * floating-point numbers. |
97 | 95 | */ |
98 | 96 |
|
99 | 97 | UNSIGNED_INT8 = 0, |
@@ -2011,24 +2009,10 @@ typecode_to_mformat_code(char typecode) |
2011 | 2009 | return UTF32_LE + is_big_endian; |
2012 | 2010 |
|
2013 | 2011 | case 'f': |
2014 | | - if (sizeof(float) == 4) { |
2015 | | - const float y = 16711938.0; |
2016 | | - if (memcmp(&y, "\x4b\x7f\x01\x02", 4) == 0) |
2017 | | - return IEEE_754_FLOAT_BE; |
2018 | | - if (memcmp(&y, "\x02\x01\x7f\x4b", 4) == 0) |
2019 | | - return IEEE_754_FLOAT_LE; |
2020 | | - } |
2021 | | - return UNKNOWN_FORMAT; |
| 2012 | + return _PY_FLOAT_BIG_ENDIAN ? IEEE_754_FLOAT_BE : IEEE_754_FLOAT_LE; |
2022 | 2013 |
|
2023 | 2014 | case 'd': |
2024 | | - if (sizeof(double) == 8) { |
2025 | | - const double x = 9006104071832581.0; |
2026 | | - if (memcmp(&x, "\x43\x3f\xff\x01\x02\x03\x04\x05", 8) == 0) |
2027 | | - return IEEE_754_DOUBLE_BE; |
2028 | | - if (memcmp(&x, "\x05\x04\x03\x02\x01\xff\x3f\x43", 8) == 0) |
2029 | | - return IEEE_754_DOUBLE_LE; |
2030 | | - } |
2031 | | - return UNKNOWN_FORMAT; |
| 2015 | + return _PY_FLOAT_BIG_ENDIAN ? IEEE_754_DOUBLE_BE : IEEE_754_DOUBLE_LE; |
2032 | 2016 |
|
2033 | 2017 | /* Integers */ |
2034 | 2018 | case 'h': |
|
0 commit comments