1616 definitions in <math.h> are actually #define'd and are not usable
1717 as function pointers :-/ */
1818
19- #if _MSC_VER < 1400 // 1310 == MSVC 7.1
20- /* Apparently, single precision functions are not included in MSVC 7.1 */
21-
22- #define sqrtf (x ) ((float )sqrt((double )(x)))
23- #define sinf (x ) ((float )sin((double )(x)))
24- #define cosf (x ) ((float )cos((double )(x)))
25- #define tanf (x ) ((float )tan((double )(x)))
26- #define asinf (x ) ((float )asin((double )(x)))
27- #define acosf (x ) ((float )acos((double )(x)))
28- #define atanf (x ) ((float )atan((double )(x)))
29- #define sinhf (x ) ((float )sinh((double )(x)))
30- #define coshf (x ) ((float )cosh((double )(x)))
31- #define tanhf (x ) ((float )tanh((double )(x)))
32- #define asinhf (x ) ((float )asinh((double )(x)))
33- #define acoshf (x ) ((float )acosh((double )(x)))
34- #define atanhf (x ) ((float )atanh((double )(x)))
35- #define logf (x ) ((float )log((double )(x)))
36- #define log1pf (x ) ((float )log1p((double )(x)))
37- #define log10f (x ) ((float )log10((double )(x)))
38- #define log2f (x ) ((float )log2((double )(x)))
39- #define expf (x ) ((float )exp((double )(x)))
40- #define expm1f (x ) ((float )expm1((double )(x)))
41- #define fabsf (x ) ((float )fabs((double )(x)))
42- #define fmodf (x, y ) ((float )fmod((double )(x), (double )(y)))
43- #define atan2f (x, y ) ((float )atan2((double )(x), (double )(y)))
44- #define hypotf (x, y ) ((float )hypot((double )(x), (double )(y)))
45- #define copysignf (x, y ) ((float )copysign((double )(x), (double )(y)))
46- #define nextafterf (x, y ) ((float )nextafter((double )(x), (double )(y)))
47- #define fmaxf (x, y ) ((float )fmaxd((double )(x), (double )(y)))
48- #define fminf (x, y ) ((float )fmind((double )(x), (double )(y)))
49- #define ceilf (x ) ((float )ceil((double )(x)))
50- #define hypotf (x ) ((float )hypot((double )(x)))
51- #define rintf (x ) ((float )rint((double )(x)))
52- #define truncf (x ) ((float )trunc((double )(x)))
53-
54-
55- /* The next are directly called from interp_body.cpp */
56- #define powf (x, y ) ((float )pow((double )(x), (double )(y)))
57- #define floorf (x ) ((float )floor((double )(x)))
58- #endif // _MSC_VER < 1400
59-
6019/* Due to casting problems (normally return ints not bools, easiest to define
6120non-overloaded wrappers for these functions) */
6221// MSVC version: use global ::isfinite / ::isnan
@@ -67,6 +26,57 @@ inline bool isnand(double x) { return !!::_isnan(x); }
6726inline bool isinfd (double x) { return !!::isinf (x); }
6827inline bool isinff_ (float x) { return !!::isinf (x); }
6928
29+ // To handle overloading of fmax/fmin in cmath and match NumPy behaviour for NaNs
30+ inline double fmaxd (double x, double y) { return (isnand (x) | isnand (y))? NAN : fmax (x, y); }
31+ inline double fmind (double x, double y) { return (isnand (x) | isnand (y))? NAN : fmin (x, y); }
32+
33+
34+ #if _MSC_VER < 1400 // 1310 == MSVC 7.1
35+ /* Apparently, single precision functions are not included in MSVC 7.1 */
36+
37+ #define sqrtf (x ) ((float )sqrt((double )(x)))
38+ #define sinf (x ) ((float )sin((double )(x)))
39+ #define cosf (x ) ((float )cos((double )(x)))
40+ #define tanf (x ) ((float )tan((double )(x)))
41+ #define asinf (x ) ((float )asin((double )(x)))
42+ #define acosf (x ) ((float )acos((double )(x)))
43+ #define atanf (x ) ((float )atan((double )(x)))
44+ #define sinhf (x ) ((float )sinh((double )(x)))
45+ #define coshf (x ) ((float )cosh((double )(x)))
46+ #define tanhf (x ) ((float )tanh((double )(x)))
47+ #define asinhf (x ) ((float )asinh((double )(x)))
48+ #define acoshf (x ) ((float )acosh((double )(x)))
49+ #define atanhf (x ) ((float )atanh((double )(x)))
50+ #define logf (x ) ((float )log((double )(x)))
51+ #define log1pf (x ) ((float )log1p((double )(x)))
52+ #define log10f (x ) ((float )log10((double )(x)))
53+ #define log2f (x ) ((float )log2((double )(x)))
54+ #define expf (x ) ((float )exp((double )(x)))
55+ #define expm1f (x ) ((float )expm1((double )(x)))
56+ #define fabsf (x ) ((float )fabs((double )(x)))
57+ #define fmodf (x, y ) ((float )fmod((double )(x), (double )(y)))
58+ #define atan2f (x, y ) ((float )atan2((double )(x), (double )(y)))
59+ #define hypotf (x, y ) ((float )hypot((double )(x), (double )(y)))
60+ #define copysignf (x, y ) ((float )copysign((double )(x), (double )(y)))
61+ #define nextafterf (x, y ) ((float )nextafter((double )(x), (double )(y)))
62+ #define ceilf (x ) ((float )ceil((double )(x)))
63+ #define hypotf (x ) ((float )hypot((double )(x)))
64+ #define rintf (x ) ((float )rint((double )(x)))
65+ #define truncf (x ) ((float )trunc((double )(x)))
66+
67+
68+ /* The next are directly called from interp_body.cpp */
69+ #define powf (x, y ) ((float )pow((double )(x), (double )(y)))
70+ #define floorf (x ) ((float )floor((double )(x)))
71+
72+ #define fmaxf_ (x, y ) ((float )fmaxd((double )(x), (double )(y))) // define fmaxf_ since fmaxf doesn't exist for early MSVC
73+ #define fminf_ (x, y ) ((float )fmind((double )(x), (double )(y)))
74+ #else
75+ inline float fmaxf_ (float x, float y) { return (isnanf_ (x) | isnanf_ (y))? NAN : fmaxf (x, y); }
76+ inline float fminf_ (float x, float y) { return (isnanf_ (x) | isnanf_ (y))? NAN : fminf (x, y); }
77+ #endif // _MSC_VER < 1400
78+
79+
7080/* Now the actual stubs */
7181
7282inline float sqrtf2 (float x) {
@@ -170,11 +180,11 @@ inline float copysignf2(float x, float y) {
170180}
171181
172182inline float fmaxf2 (float x, float y) {
173- return fmaxf (x, y);
183+ return fmaxf_ (x, y);
174184}
175185
176186inline float fminf2 (float x, float y) {
177- return fminf (x, y);
187+ return fminf_ (x, y);
178188}
179189
180190
0 commit comments