From c8ea21327dbb48103bfa8d6349c6ee587f3b4a43 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 10 Nov 2024 10:18:48 +0800 Subject: [PATCH] Fix cmath --- scipy/spatial/ckdtree/src/build.cxx | 4 ++++ scipy/special/Faddeeva.cc | 2 ++ scipy/special/_round.h | 5 +++++ scipy/special/boost_special_functions.h | 10 +++++----- scipy/special/special/bessel.h | 24 ++++++++++++------------ scipy/special/special/par_cyl.h | 5 +++++ scipy/special/special/sph_bessel.h | 12 ++++++------ scipy/special/stirling2.h | 5 +++++ scipy/special/wright.cc | 2 ++ 9 files changed, 46 insertions(+), 23 deletions(-) diff --git scipy/spatial/ckdtree/src/build.cxx scipy/spatial/ckdtree/src/build.cxx index f6a064d06..1083fc16f 100644 --- scipy/spatial/ckdtree/src/build.cxx +++ scipy/spatial/ckdtree/src/build.cxx @@ -13,6 +13,10 @@ #include #include +#if defined(__cplusplus) +using std::isinf; +#endif + #define tree_buffer_root(buf) (&(buf)[0][0]) static ckdtree_intp_t diff --git scipy/special/Faddeeva.cc scipy/special/Faddeeva.cc index 370516dc0..8148fe60b 100644 --- scipy/special/Faddeeva.cc +++ scipy/special/Faddeeva.cc @@ -122,6 +122,8 @@ #include #define complex std::complex +#define isinf std::isinf +#define isnan std::isnan ///////////////////////////////////////////////////////////////////////// diff --git scipy/special/_round.h scipy/special/_round.h index 91447c260..a251f2327 100644 --- scipy/special/_round.h +++ scipy/special/_round.h @@ -5,6 +5,11 @@ #ifndef ROUND_H #define ROUND_H +#if defined(__cplusplus) +#include +using std::isnan; +#endif + #include diff --git scipy/special/boost_special_functions.h scipy/special/boost_special_functions.h index 668aa7a9c..0e79c2ec4 100644 --- scipy/special/boost_special_functions.h +++ scipy/special/boost_special_functions.h @@ -78,7 +78,7 @@ Real ibeta_wrap(Real a, Real b, Real x) { Real y; - if (isnan(a) || isnan(b) || isnan(x)) { + if (std::isnan(a) || std::isnan(b) || std::isnan(x)) { return NAN; } if ((a <= 0) || (b <= 0) || (x < 0) || (x > 1)) { @@ -122,7 +122,7 @@ Real ibetac_wrap(Real a, Real b, Real x) { Real y; - if (isnan(a) || isnan(b) || isnan(x)) { + if (std::isnan(a) || std::isnan(b) || std::isnan(x)) { return NAN; } if ((a <= 0) || (b <= 0) || (x < 0) || (x > 1)) { @@ -166,7 +166,7 @@ Real ibeta_inv_wrap(Real a, Real b, Real p, const Policy& policy_) { Real y; - if (isnan(a) || isnan(b) || isnan(p)) { + if (std::isnan(a) || std::isnan(b) || std::isnan(p)) { return NAN; } if ((a <= 0) || (b <= 0) || (p < 0) || (p > 1)) { @@ -210,7 +210,7 @@ Real ibetac_inv_wrap(Real a, Real b, Real p) { Real y; - if (isnan(a) || isnan(b) || isnan(p)) { + if (std::isnan(a) || std::isnan(b) || std::isnan(p)) { return NAN; } if ((a <= 0) || (b <= 0) || (p < 0) || (p > 1)) { @@ -428,7 +428,7 @@ Real hyp1f1_wrap(Real a, Real b, Real x) { Real y; - if (isnan(a) || isnan(b) || isnan(x)) { + if (std::isnan(a) || std::isnan(b) || std::isnan(x)) { return NAN; } if (b <= 0 && std::trunc(b) == b) { diff --git scipy/special/special/bessel.h scipy/special/special/bessel.h index 4532cc97f..85e17224a 100644 --- scipy/special/special/bessel.h +++ scipy/special/special/bessel.h @@ -600,7 +600,7 @@ inline std::complex cyl_bessel_je(double v, std::complex z) { cy_y.real(NAN); cy_y.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy_j; } if (v < 0) { @@ -645,7 +645,7 @@ inline std::complex cyl_bessel_ye(double v, std::complex z) { cy_y.real(NAN); cy_y.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy_y; } if (v < 0) { @@ -698,7 +698,7 @@ inline std::complex cyl_bessel_ie(double v, std::complex z) { cy_k.real(NAN); cy_k.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } if (v < 0) { @@ -742,7 +742,7 @@ T cyl_bessel_ie(T v, T x) { inline std::complex cyl_bessel_ke(double v, std::complex z) { std::complex cy{NAN, NAN}; - if (isnan(v) || isnan(std::real(z)) || isnan(std::imag(z))) { + if (std::isnan(v) || std::isnan(std::real(z)) || std::isnan(std::imag(z))) { return cy; } @@ -795,7 +795,7 @@ inline std::complex cyl_hankel_1e(double v, std::complex z) { cy.real(NAN); cy.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } if (v < 0) { @@ -823,7 +823,7 @@ inline std::complex cyl_hankel_2e(double v, std::complex z) { int sign = 1; std::complex cy{NAN, NAN}; - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } @@ -856,7 +856,7 @@ inline std::complex cyl_bessel_j(double v, std::complex z) { cy_y.real(NAN); cy_y.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy_j; } if (v < 0) { @@ -914,7 +914,7 @@ inline std::complex cyl_bessel_y(double v, std::complex z) { cy_y.real(NAN); cy_y.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy_y; } if (v < 0) { @@ -985,7 +985,7 @@ inline std::complex cyl_bessel_i(double v, std::complex z) { cy_k.real(NAN); cy_k.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } if (v < 0) { @@ -1026,7 +1026,7 @@ inline std::complex cyl_bessel_i(float v, std::complex x) { inline std::complex cyl_bessel_k(double v, std::complex z) { std::complex cy(NAN, NAN); - if (std::isnan(v) || std::isnan(std::real(z)) || isnan(std::imag(z))) { + if (std::isnan(v) || std::isnan(std::real(z)) || std::isnan(std::imag(z))) { return cy; } @@ -1086,7 +1086,7 @@ inline std::complex cyl_hankel_1(double v, std::complex z) { cy.real(NAN); cy.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } if (v < 0) { @@ -1116,7 +1116,7 @@ inline std::complex cyl_hankel_2(double v, std::complex z) { cy.real(NAN); cy.imag(NAN); - if (isnan(v) || isnan(z.real()) || isnan(z.imag())) { + if (std::isnan(v) || std::isnan(z.real()) || std::isnan(z.imag())) { return cy; } if (v < 0) { diff --git scipy/special/special/par_cyl.h scipy/special/special/par_cyl.h index eae11ff8a..b37fb2125 100644 --- scipy/special/special/par_cyl.h +++ scipy/special/special/par_cyl.h @@ -2,6 +2,11 @@ #include "specfun/specfun.h" +#if defined(__cplusplus) +#include +using std::isnan; +#endif + namespace special { namespace detail { diff --git scipy/special/special/sph_bessel.h scipy/special/special/sph_bessel.h index 9e356764a..59d270ac3 100644 --- scipy/special/special/sph_bessel.h +++ scipy/special/special/sph_bessel.h @@ -144,7 +144,7 @@ T sph_bessel_y(long n, T x) { T s0, s1, sn; int idx; - if (isnan(x)) { + if (std::isnan(x)) { return x; } @@ -179,7 +179,7 @@ T sph_bessel_y(long n, T x) { sn = (2 * idx + 3) * s1 / x - s0; s0 = s1; s1 = sn; - if (isinf(sn)) { + if (std::isinf(sn)) { // Overflow occurred already: terminate recurrence. return sn; } @@ -229,7 +229,7 @@ T sph_bessel_y_jac(long n, T x) { template T sph_bessel_i(long n, T x) { - if (isnan(x)) { + if (std::isnan(x)) { return x; } @@ -246,7 +246,7 @@ T sph_bessel_i(long n, T x) { return 0; } - if (isinf(x)) { + if (std::isinf(x)) { // https://dlmf.nist.gov/10.49.E8 if (x == -std::numeric_limits::infinity()) { return std::pow(-1, n) * std::numeric_limits::infinity(); @@ -314,7 +314,7 @@ T sph_bessel_i_jac(long n, T z) { template T sph_bessel_k(long n, T z) { - if (isnan(z)) { + if (std::isnan(z)) { return z; } @@ -327,7 +327,7 @@ T sph_bessel_k(long n, T z) { return std::numeric_limits::infinity(); } - if (isinf(z)) { + if (std::isinf(z)) { // https://dlmf.nist.gov/10.52.E6 if (z == std::numeric_limits::infinity()) { return 0; diff --git scipy/special/stirling2.h scipy/special/stirling2.h index 9120be008..88043b6d0 100644 --- scipy/special/stirling2.h +++ scipy/special/stirling2.h @@ -1,6 +1,11 @@ #ifndef STIRLING_H #define STIRLING_H +#if defined(__cplusplus) +#include +using std::isinf; +#endif + #include #include #include diff --git scipy/special/wright.cc scipy/special/wright.cc index 00c042516..5d199a41a 100644 --- scipy/special/wright.cc +++ scipy/special/wright.cc @@ -84,6 +84,8 @@ extern "C" { #include "sf_error.h" using std::complex; +using std::isinf; +using std::isnan; #define TWOITERTOL DBL_EPSILON