diff options
| author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-14 11:23:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-14 11:23:53 -0700 |
| commit | 54c2c1ebd290c2cc2faa6f6272f4b04fd0c1eea5 (patch) | |
| tree | 5c9f943d965e85845e48c8147f958e1569b5ca4e /numpy | |
| parent | a5535dc6242b0decae1e65a3d4feb220fefedc49 (diff) | |
| parent | 7be59f1787f6a900b8fe4a0013ba3e9f2b7cea95 (diff) | |
| download | numpy-54c2c1ebd290c2cc2faa6f6272f4b04fd0c1eea5.tar.gz | |
Merge pull request #21732 from hoodmane/fenv-missing-flags
ENH: Add support for platforms with missing fenv flags
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/npymath/ieee754.c.src | 24 | ||||
| -rw-r--r-- | numpy/core/src/npymath/ieee754.cpp | 24 |
2 files changed, 48 insertions, 0 deletions
diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src index 6dc9cf2f8..5d1ea3a69 100644 --- a/numpy/core/src/npymath/ieee754.c.src +++ b/numpy/core/src/npymath/ieee754.c.src @@ -575,6 +575,30 @@ int npy_get_floatstatus() { */ # include <fenv.h> +/* + * According to the C99 standard FE_DIVBYZERO, etc. may not be provided when + * unsupported. In such cases NumPy will not report these correctly, but we + * should still allow compiling (whether tests pass or not). + * By defining them as 0 locally, we make them no-ops. Unlike these defines, + * for example `musl` still defines all of the functions (as no-ops): + * https://git.musl-libc.org/cgit/musl/tree/src/fenv/fenv.c + * and does similar replacement in its tests: + * http://nsz.repo.hu/git/?p=libc-test;a=blob;f=src/common/mtest.h;h=706c1ba23ea8989b17a2f72ed1a919e187c06b6a;hb=HEAD#l30 + */ +#ifndef FE_DIVBYZERO + #define FE_DIVBYZERO 0 +#endif +#ifndef FE_OVERFLOW + #define FE_OVERFLOW 0 +#endif +#ifndef FE_UNDERFLOW + #define FE_UNDERFLOW 0 +#endif +#ifndef FE_INVALID + #define FE_INVALID 0 +#endif + + int npy_get_floatstatus_barrier(char* param) { int fpstatus = fetestexcept(FE_DIVBYZERO | FE_OVERFLOW | diff --git a/numpy/core/src/npymath/ieee754.cpp b/numpy/core/src/npymath/ieee754.cpp index 2244004c0..27fcf7c6e 100644 --- a/numpy/core/src/npymath/ieee754.cpp +++ b/numpy/core/src/npymath/ieee754.cpp @@ -655,6 +655,30 @@ npy_get_floatstatus() */ #include <fenv.h> +/* + * According to the C99 standard FE_DIVBYZERO, etc. may not be provided when + * unsupported. In such cases NumPy will not report these correctly, but we + * should still allow compiling (whether tests pass or not). + * By defining them as 0 locally, we make them no-ops. Unlike these defines, + * for example `musl` still defines all of the functions (as no-ops): + * https://git.musl-libc.org/cgit/musl/tree/src/fenv/fenv.c + * and does similar replacement in its tests: + * http://nsz.repo.hu/git/?p=libc-test;a=blob;f=src/common/mtest.h;h=706c1ba23ea8989b17a2f72ed1a919e187c06b6a;hb=HEAD#l30 + */ +#ifndef FE_DIVBYZERO + #define FE_DIVBYZERO 0 +#endif +#ifndef FE_OVERFLOW + #define FE_OVERFLOW 0 +#endif +#ifndef FE_UNDERFLOW + #define FE_UNDERFLOW 0 +#endif +#ifndef FE_INVALID + #define FE_INVALID 0 +#endif + + extern "C" int npy_get_floatstatus_barrier(char *param) { |
