|
1 | 1 | #include <math.h>
|
2 | 2 | #ifdef MS_WIN32
|
3 | 3 | #include "malloc.h"
|
| 4 | +/* |
| 5 | +note: the following implicitly sets a mininum VS version: conservative |
| 6 | +minimum is _MSC_VER >= 1928 (VS 2019, 16.8), but may work for VS 2015 |
| 7 | +but that has not been tested. see https://github.com/yt-project/yt/pull/4980 |
| 8 | +and https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance |
| 9 | +*/ |
4 | 10 | #include <float.h>
|
5 |
| -typedef int int32_t; |
6 |
| -typedef long long int64_t; |
7 |
| -/* Taken from http://siliconandlithium.blogspot.com/2014/05/msvc-c99-mathh-header.html */ |
8 |
| -#define isnormal(x) ((_fpclass(x) == _FPCLASS_NN) || (_fpclass(x) == _FPCLASS_PN)) |
9 |
| -static __inline double rint(double x){ |
10 |
| - const double two_to_52 = 4.5035996273704960e+15; |
11 |
| - double fa = fabs(x); |
12 |
| - if(fa >= two_to_52){ |
13 |
| - return x; |
14 |
| - } else{ |
15 |
| - return copysign(two_to_52 + fa - two_to_52, x); |
16 |
| - } |
17 |
| -} |
18 |
| -#if _MSC_VER < 1928 |
19 |
| -static __inline long int lrint(double x){ |
20 |
| - return (long)rint(x); |
21 |
| -} |
22 |
| -#endif |
23 |
| -static __inline double fmax(double x, double y){ |
24 |
| - return (x > y) ? x : y; |
25 |
| -} |
26 |
| -static __inline double fmin(double x, double y){ |
27 |
| - return (x < y) ? x : y; |
28 |
| -} |
29 |
| - |
30 |
| -/* adapted from http://www.johndcook.com/blog/cpp_erf/ |
31 |
| - code is under public domain license */ |
32 |
| - |
33 |
| -double erf(double x) |
34 |
| -{ |
35 |
| - /* constants */ |
36 |
| - double a1 = 0.254829592; |
37 |
| - double a2 = -0.284496736; |
38 |
| - double a3 = 1.421413741; |
39 |
| - double a4 = -1.453152027; |
40 |
| - double a5 = 1.061405429; |
41 |
| - double p = 0.3275911; |
42 |
| - double t; |
43 |
| - double y; |
44 |
| - |
45 |
| - /* Save the sign of x */ |
46 |
| - int sign = 1; |
47 |
| - if (x < 0) |
48 |
| - sign = -1; |
49 |
| - x = fabs(x); |
50 |
| - |
51 |
| - /* A&S formula 7.1.26 */ |
52 |
| - t = 1.0/(1.0 + p*x); |
53 |
| - y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x); |
54 |
| - |
55 |
| - return sign*y; |
56 |
| -} |
| 11 | +#include <stdint.h> |
57 | 12 | #elif defined(__FreeBSD__)
|
58 | 13 | #include <stdint.h>
|
59 | 14 | #include <stdlib.h>
|
|
0 commit comments