[CMAKE]
[reactos.git] / include / crt / math.h
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER within this package.
5 */
6 #ifndef _INC_MATH
7 #define _INC_MATH
8
9 #include <crtdefs.h>
10
11 struct exception;
12
13 #pragma pack(push,_CRT_PACKING)
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #ifndef _EXCEPTION_DEFINED
20 #define _EXCEPTION_DEFINED
21 struct _exception {
22 int type;
23 char *name;
24 double arg1;
25 double arg2;
26 double retval;
27 };
28 #endif
29
30 #ifndef _COMPLEX_DEFINED
31 #define _COMPLEX_DEFINED
32 struct _complex {
33 double x,y;
34 };
35 #endif
36
37 #define _DOMAIN 1
38 #define _SING 2
39 #define _OVERFLOW 3
40 #define _UNDERFLOW 4
41 #define _TLOSS 5
42 #define _PLOSS 6
43 #define EDOM 33
44 #define ERANGE 34
45
46 _CRTIMP extern double _HUGE;
47
48 #define HUGE_VAL _HUGE
49 #define _matherrl _matherr
50
51 #ifndef _CRT_ABS_DEFINED
52 #define _CRT_ABS_DEFINED
53 int __cdecl abs(int x);
54 long __cdecl labs(long x);
55 #endif
56 double __cdecl acos(double x);
57 double __cdecl asin(double x);
58 double __cdecl atan(double x);
59 double __cdecl atan2(double y, double x);
60 double __cdecl cos(double x);
61 double __cdecl cosh(double x);
62 double __cdecl exp(double x);
63 double __cdecl fabs(double x);
64 double __cdecl fmod(double x, double y);
65 double __cdecl log(double x);
66 double __cdecl log10(double x);
67 double __cdecl pow(double x, double y);
68 double __cdecl sin(double x);
69 double __cdecl sinh(double x);
70 double __cdecl sqrt(double x);
71 double __cdecl tan(double x);
72 double __cdecl tanh(double x);
73 #ifndef _CRT_MATHERR_DEFINED
74 #define _CRT_MATHERR_DEFINED
75 int __cdecl _matherr(struct _exception *except);
76 #endif
77
78 #ifndef _CRT_ATOF_DEFINED
79 #define _CRT_ATOF_DEFINED
80 _CRTIMP double __cdecl atof(const char *str);
81 _CRTIMP double __cdecl _atof_l(const char *str ,_locale_t locale);
82 #endif
83 #ifndef _SIGN_DEFINED
84 #define _SIGN_DEFINED
85 _CRTIMP double __cdecl _copysign(double x,double sgn);
86 _CRTIMP double __cdecl _chgsign(double x);
87 #endif
88 _CRTIMP double __cdecl _cabs(struct _complex a);
89 _CRTIMP double __cdecl ceil(double x);
90 _CRTIMP double __cdecl floor(double x);
91 _CRTIMP double __cdecl frexp(double x, int *y);
92 _CRTIMP double __cdecl _hypot(double x, double y);
93 _CRTIMP double __cdecl _j0(double x);
94 _CRTIMP double __cdecl _j1(double x);
95 _CRTIMP double __cdecl _jn(int x, double y);
96 _CRTIMP double __cdecl ldexp(double x, int y);
97 _CRTIMP double __cdecl modf(double x, double *y);
98 _CRTIMP double __cdecl _y0(double x);
99 _CRTIMP double __cdecl _y1(double x);
100 _CRTIMP double __cdecl _yn(int x, double y);
101 _CRTIMP float __cdecl _hypotf(float x, float y);
102
103 #if defined(__i386__) || defined(_M_IX86)
104 _CRTIMP int __cdecl _set_SSE2_enable(int flag);
105 #endif
106
107 #if defined(__x86_64) || defined(_M_AMD64)
108 _CRTIMP float __cdecl _copysignf(float x, float sgn);
109 _CRTIMP float __cdecl _chgsignf(float x);
110 _CRTIMP float __cdecl _logbf(float x);
111 _CRTIMP float __cdecl _nextafterf(float x,float y);
112 _CRTIMP int __cdecl _finitef(float x);
113 _CRTIMP int __cdecl _isnanf(float x);
114 _CRTIMP int __cdecl _fpclassf(float x);
115 #endif
116
117 #if defined(__ia64__) || defined (_M_IA64)
118 _CRTIMP float __cdecl fabsf(float x);
119 _CRTIMP float __cdecl ldexpf(float x, int y);
120 _CRTIMP long double __cdecl tanl(long double x);
121 #else
122 __CRT_INLINE float __cdecl fabsf(float x) { return ((float)fabs((double)x)); }
123 __CRT_INLINE float __cdecl ldexpf(float x, int expn) { return (float)ldexp (x, expn); }
124 __CRT_INLINE long double tanl(long double x) { return (tan((double)x)); }
125 #endif
126
127 #if defined(__x86_64) || defined(_M_AMD64) || \
128 defined (__ia64__) || defined (_M_IA64)
129 _CRTIMP float __cdecl acosf(float x);
130 _CRTIMP float __cdecl asinf(float x);
131 _CRTIMP float __cdecl atanf(float x);
132 _CRTIMP float __cdecl atan2f(float x, float y);
133 _CRTIMP float __cdecl ceilf(float x);
134 _CRTIMP float __cdecl cosf(float x);
135 _CRTIMP float __cdecl coshf(float x);
136 _CRTIMP float __cdecl expf(float x);
137 _CRTIMP float __cdecl floorf(float x);
138 _CRTIMP float __cdecl fmodf(float x, float y);
139 _CRTIMP float __cdecl logf(float x);
140 _CRTIMP float __cdecl log10f(float x);
141 _CRTIMP float __cdecl modff(float x, float *y);
142 _CRTIMP float __cdecl powf(float b, float e);
143 _CRTIMP float __cdecl sinf(float x);
144 _CRTIMP float __cdecl sinhf(float x);
145 _CRTIMP float __cdecl sqrtf(float x);
146 _CRTIMP float __cdecl tanf(float x);
147 _CRTIMP float __cdecl tanhf(float x);
148 #else
149 __CRT_INLINE float acosf(float x) { return ((float)acos((double)x)); }
150 __CRT_INLINE float asinf(float x) { return ((float)asin((double)x)); }
151 __CRT_INLINE float atanf(float x) { return ((float)atan((double)x)); }
152 __CRT_INLINE float atan2f(float x,float y) { return ((float)atan2((double)x,(double)y)); }
153 __CRT_INLINE float ceilf(float x) { return ((float)ceil((double)x)); }
154 __CRT_INLINE float cosf(float x) { return ((float)cos((double)x)); }
155 __CRT_INLINE float coshf(float x) { return ((float)cosh((double)x)); }
156 __CRT_INLINE float expf(float x) { return ((float)exp((double)x)); }
157 __CRT_INLINE float floorf(float x) { return ((float)floor((double)x)); }
158 __CRT_INLINE float fmodf(float x,float y) { return ((float)fmod((double)x,(double)y)); }
159 __CRT_INLINE float logf(float x) { return ((float)log((double)x)); }
160 __CRT_INLINE float log10f(float x) { return ((float)log10((double)x)); }
161 __CRT_INLINE float modff(float x,float *y) {
162 double _Di,_Df = modf((double)x,&_Di);
163 *y = (float)_Di;
164 return ((float)_Df);
165 }
166 __CRT_INLINE float powf(float x,float y) { return ((float)pow((double)x,(double)y)); }
167 __CRT_INLINE float sinf(float x) { return ((float)sin((double)x)); }
168 __CRT_INLINE float sinhf(float x) { return ((float)sinh((double)x)); }
169 __CRT_INLINE float sqrtf(float x) { return ((float)sqrt((double)x)); }
170 __CRT_INLINE float tanf(float x) { return ((float)tan((double)x)); }
171 __CRT_INLINE float tanhf(float x) { return ((float)tanh((double)x)); }
172 #endif
173
174 __CRT_INLINE long double acosl(long double x) { return (acos((double)x)); }
175 __CRT_INLINE long double asinl(long double x) { return (asin((double)x)); }
176 __CRT_INLINE long double atanl(long double x) { return (atan((double)x)); }
177 __CRT_INLINE long double atan2l(long double y, long double x) { return (atan2((double)y, (double)x)); }
178 __CRT_INLINE long double ceill(long double x) { return (ceil((double)x)); }
179 __CRT_INLINE long double cosl(long double x) { return (cos((double)x)); }
180 __CRT_INLINE long double coshl(long double x) { return (cosh((double)x)); }
181 __CRT_INLINE long double expl(long double x) { return (exp((double)x)); }
182 __CRT_INLINE long double floorl(long double x) { return (floor((double)x)); }
183 __CRT_INLINE long double fmodl(long double x, long double y) { return (fmod((double)x, (double)y)); }
184 __CRT_INLINE long double frexpl(long double x, int *y) { return (frexp((double)x, y)); }
185 __CRT_INLINE long double logl(long double x) { return (log((double)x)); }
186 __CRT_INLINE long double log10l(long double x) { return (log10((double)x)); }
187 __CRT_INLINE long double powl(long double x, long double y) { return (pow((double)x, (double)y)); }
188 __CRT_INLINE long double sinl(long double x) { return (sin((double)x)); }
189 __CRT_INLINE long double sinhl(long double x) { return (sinh((double)x)); }
190 __CRT_INLINE long double sqrtl(long double x) { return (sqrt((double)x)); }
191 __CRT_INLINE long double tanhl(long double x) {return (tanh((double)x)); }
192 __CRT_INLINE long double __cdecl fabsl(long double x) { return fabs((double)x); }
193 __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign((double)(_Number)); }
194 __CRT_INLINE long double _copysignl(long double _Number, long double _Sign) { return _copysign((double)(_Number),(double)(_Sign)); }
195 __CRT_INLINE long double _hypotl(long double x,long double y) { return _hypot((double)(x),(double)(y)); }
196 __CRT_INLINE float frexpf(float x, int *y) { return ((float)frexp((double)x,y)); }
197 __CRT_INLINE long double ldexpl(long double x, int y) { return ldexp((double)x, y); }
198 __CRT_INLINE long double modfl(long double x,long double *y) {
199 double _Di,_Df = modf((double)x,&_Di);
200 *y = (long double)_Di;
201 return (_Df);
202 }
203
204 #ifndef NO_OLDNAMES
205 #define DOMAIN _DOMAIN
206 #define SING _SING
207 #define OVERFLOW _OVERFLOW
208 #define UNDERFLOW _UNDERFLOW
209 #define TLOSS _TLOSS
210 #define PLOSS _PLOSS
211 #define matherr _matherr
212 #define HUGE _HUGE
213 // _CRTIMP double __cdecl cabs(struct _complex x);
214 #define cabs _cabs
215 _CRTIMP double __cdecl hypot(double x,double y);
216 _CRTIMP double __cdecl j0(double x);
217 _CRTIMP double __cdecl j1(double x);
218 _CRTIMP double __cdecl jn(int x,double y);
219 _CRTIMP double __cdecl y0(double x);
220 _CRTIMP double __cdecl y1(double x);
221 _CRTIMP double __cdecl yn(int x,double y);
222 __CRT_INLINE float __cdecl hypotf(float x, float y) { return (float) hypot (x, y); }
223 #endif
224
225 #ifdef __cplusplus
226 }
227 extern "C++" {
228 template<class _Ty> inline _Ty _Pow_int(_Ty x,int y) {
229 unsigned int _N;
230 if(y >= 0) _N = (unsigned int)y;
231 else _N = (unsigned int)(-y);
232 for(_Ty _Z = _Ty(1);;x *= x) {
233 if((_N & 1)!=0) _Z *= x;
234 if((_N >>= 1)==0) return (y < 0 ? _Ty(1) / _Z : _Z);
235 }
236 }
237 }
238 #endif
239
240 #pragma pack(pop)
241
242 #endif /* !_INC_MATH */
243
244 #if defined(_USE_MATH_DEFINES) && !defined(_MATH_DEFINES_DEFINED)
245 #define _MATH_DEFINES_DEFINED
246
247 #define M_E 2.71828182845904523536
248 #define M_LOG2E 1.44269504088896340736
249 #define M_LOG10E 0.434294481903251827651
250 #define M_LN2 0.693147180559945309417
251 #define M_LN10 2.30258509299404568402
252 #define M_PI 3.14159265358979323846
253 #define M_PI_2 1.57079632679489661923
254 #define M_PI_4 0.785398163397448309616
255 #define M_1_PI 0.318309886183790671538
256 #define M_2_PI 0.636619772367581343076
257 #define M_2_SQRTPI 1.12837916709551257390
258 #define M_SQRT2 1.41421356237309504880
259 #define M_SQRT1_2 0.707106781186547524401
260
261 #endif /* _USE_MATH_DEFINES */