- Try to fix build
[reactos.git] / reactos / 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
44 #define EDOM 33
45 #define ERANGE 34
46
47 _CRTIMP extern double _HUGE;
48
49 #define HUGE_VAL _HUGE
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 #ifndef _SIGN_DEFINED
61 #define _SIGN_DEFINED
62 _CRTIMP double __cdecl _copysign (double _Number,double _Sign);
63 _CRTIMP double __cdecl _chgsign (double _X);
64 #endif
65 double __cdecl cos(double _X);
66 double __cdecl cosh(double _X);
67 double __cdecl exp(double _X);
68 double expm1(double _X);
69 double __cdecl fabs(double _X);
70 double __cdecl fmod(double _X,double _Y);
71 double __cdecl log(double _X);
72 double __cdecl log10(double _X);
73 double __cdecl pow(double _X,double _Y);
74 double __cdecl sin(double _X);
75 double __cdecl sinh(double _X);
76 double __cdecl tan(double _X);
77 double __cdecl tanh(double _X);
78 double __cdecl sqrt(double _X);
79 #ifndef _CRT_ATOF_DEFINED
80 #define _CRT_ATOF_DEFINED
81 double __cdecl atof(const char *_String);
82 double __cdecl _atof_l(const char *_String,_locale_t _Locale);
83 #endif
84
85 _CRTIMP double __cdecl _cabs(struct _complex _ComplexA);
86 _CRTIMP double __cdecl ceil(double _X);
87 _CRTIMP double __cdecl floor(double _X);
88 _CRTIMP double __cdecl frexp(double _X,int *_Y);
89 _CRTIMP double __cdecl _hypot(double _X,double _Y);
90 _CRTIMP double __cdecl _j0(double _X);
91 _CRTIMP double __cdecl _j1(double _X);
92 _CRTIMP double __cdecl _jn(int _X,double _Y);
93 _CRTIMP double __cdecl ldexp(double _X,int _Y);
94 #ifndef _CRT_MATHERR_DEFINED
95 #define _CRT_MATHERR_DEFINED
96 int __cdecl _matherr(struct _exception *_Except);
97 #endif
98 _CRTIMP double __cdecl modf(double _X,double *_Y);
99 _CRTIMP double __cdecl _y0(double _X);
100 _CRTIMP double __cdecl _y1(double _X);
101 _CRTIMP double __cdecl _yn(int _X,double _Y);
102
103 #if(defined(_X86_) && !defined(__x86_64))
104 _CRTIMP int __cdecl _set_SSE2_enable(int _Flag);
105 /* from libmingwex */
106 float __cdecl _hypotf(float _X,float _Y);
107 #endif
108
109 float frexpf(float _X,int *_Y);
110 float __cdecl ldexpf(float _X,int _Y);
111 long double __cdecl ldexpl(long double _X,int _Y);
112 float __cdecl acosf(float _X);
113 float __cdecl asinf(float _X);
114 float __cdecl atanf(float _X);
115 float __cdecl atan2f(float _X,float _Y);
116 float __cdecl cosf(float _X);
117 float __cdecl sinf(float _X);
118 float __cdecl tanf(float _X);
119 float __cdecl coshf(float _X);
120 float __cdecl sinhf(float _X);
121 float __cdecl tanhf(float _X);
122 float __cdecl expf(float _X);
123 float expm1f(float _X);
124 float __cdecl logf(float _X);
125 float __cdecl log10f(float _X);
126 float __cdecl modff(float _X,float *_Y);
127 float __cdecl powf(float _X,float _Y);
128 float __cdecl sqrtf(float _X);
129 float __cdecl ceilf(float _X);
130 float __cdecl floorf(float _X);
131 float __cdecl fmodf(float _X,float _Y);
132 float __cdecl _hypotf(float _X,float _Y);
133 float __cdecl fabsf(float _X);
134 #if !defined(__ia64__)
135 /* from libmingwex */
136 float __cdecl _copysignf (float _Number,float _Sign);
137 float __cdecl _chgsignf (float _X);
138 float __cdecl _logbf(float _X);
139 float __cdecl _nextafterf(float _X,float _Y);
140 int __cdecl _finitef(float _X);
141 int __cdecl _isnanf(float _X);
142 int __cdecl _fpclassf(float _X);
143 #endif
144
145 #ifndef __cplusplus
146 __CRT_INLINE long double __cdecl fabsl (long double x)
147 {
148 long double res;
149 __asm__ ("fabs;" : "=t" (res) : "0" (x));
150 return res;
151 }
152 #define _hypotl(x,y) ((long double)_hypot((double)(x),(double)(y)))
153 #define _matherrl _matherr
154 __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign((double)(_Number)); }
155 __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign((double)(_Number),(double)(_Sign)); }
156 __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
157
158 #if !defined (__ia64__)
159 __CRT_INLINE float __cdecl fabsf (float x)
160 {
161 float res;
162 __asm__ ("fabs;" : "=t" (res) : "0" (x));
163 return res;
164 }
165
166 __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
167 #endif
168 #else
169 // cplusplus
170 __CRT_INLINE long double __cdecl fabsl (long double x)
171 {
172 long double res;
173 __asm__ ("fabs;" : "=t" (res) : "0" (x));
174 return res;
175 }
176 __CRT_INLINE long double modfl(long double _X,long double *_Y) {
177 double _Di,_Df = modf((double)_X,&_Di);
178 *_Y = (long double)_Di;
179 return (_Df);
180 }
181 __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign(static_cast<double>(_Number)); }
182 __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign(static_cast<double>(_Number),static_cast<double>(_Sign)); }
183 __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
184 #ifndef __ia64__
185 __CRT_INLINE float __cdecl fabsf (float x)
186 {
187 float res;
188 __asm__ ("fabs;" : "=t" (res) : "0" (x));
189 return res;
190 }
191 __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
192 #endif
193 #endif
194
195 #ifndef __x86_64
196 __CRT_INLINE float acosf(float _X) { return ((float)acos((double)_X)); }
197 __CRT_INLINE float asinf(float _X) { return ((float)asin((double)_X)); }
198 __CRT_INLINE float atanf(float _X) { return ((float)atan((double)_X)); }
199 __CRT_INLINE float atan2f(float _X,float _Y) { return ((float)atan2((double)_X,(double)_Y)); }
200 __CRT_INLINE float ceilf(float _X) { return ((float)ceil((double)_X)); }
201 __CRT_INLINE float cosf(float _X) { return ((float)cos((double)_X)); }
202 __CRT_INLINE float coshf(float _X) { return ((float)cosh((double)_X)); }
203 __CRT_INLINE float expf(float _X) { return ((float)exp((double)_X)); }
204 __CRT_INLINE float floorf(float _X) { return ((float)floor((double)_X)); }
205 __CRT_INLINE float fmodf(float _X,float _Y) { return ((float)fmod((double)_X,(double)_Y)); }
206 __CRT_INLINE float logf(float _X) { return ((float)log((double)_X)); }
207 __CRT_INLINE float log10f(float _X) { return ((float)log10((double)_X)); }
208 __CRT_INLINE float modff(float _X,float *_Y) {
209 double _Di,_Df = modf((double)_X,&_Di);
210 *_Y = (float)_Di;
211 return ((float)_Df);
212 }
213 __CRT_INLINE float powf(float _X,float _Y) { return ((float)pow((double)_X,(double)_Y)); }
214 __CRT_INLINE float sinf(float _X) { return ((float)sin((double)_X)); }
215 __CRT_INLINE float sinhf(float _X) { return ((float)sinh((double)_X)); }
216 __CRT_INLINE float sqrtf(float _X) { return ((float)sqrt((double)_X)); }
217 __CRT_INLINE float tanf(float _X) { return ((float)tan((double)_X)); }
218 __CRT_INLINE float tanhf(float _X) { return ((float)tanh((double)_X)); }
219 #endif
220
221 #ifndef NO_OLDNAMES
222 #define DOMAIN _DOMAIN
223 #define SING _SING
224 #define OVERFLOW _OVERFLOW
225 #define UNDERFLOW _UNDERFLOW
226 #define TLOSS _TLOSS
227 #define PLOSS _PLOSS
228 #define matherr _matherr
229
230 #define HUGE _HUGE
231 /* double __cdecl cabs(struct _complex _X); */
232 double __cdecl hypot(double _X,double _Y);
233 _CRTIMP double __cdecl j0(double _X);
234 _CRTIMP double __cdecl j1(double _X);
235 _CRTIMP double __cdecl jn(int _X,double _Y);
236 _CRTIMP double __cdecl y0(double _X);
237 _CRTIMP double __cdecl y1(double _X);
238 _CRTIMP double __cdecl yn(int _X,double _Y);
239 #endif
240
241 #ifndef __NO_ISOCEXT
242 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
243 || !defined __STRICT_ANSI__ || defined __GLIBCPP__
244
245 #define NAN (0.0F/0.0F)
246 #define HUGE_VALF (1.0F/0.0F)
247 #define HUGE_VALL (1.0L/0.0L)
248 #define INFINITY (1.0F/0.0F)
249
250
251 #define FP_NAN 0x0100
252 #define FP_NORMAL 0x0400
253 #define FP_INFINITE (FP_NAN | FP_NORMAL)
254 #define FP_ZERO 0x4000
255 #define FP_SUBNORMAL (FP_NORMAL | FP_ZERO)
256 /* 0x0200 is signbit mask */
257
258
259 /*
260 We can't __CRT_INLINE float or double, because we want to ensure truncation
261 to semantic type before classification.
262 (A normal long double value might become subnormal when
263 converted to double, and zero when converted to float.)
264 */
265
266 extern int __cdecl __fpclassifyf (float);
267 extern int __cdecl __fpclassify (double);
268
269 __CRT_INLINE int __cdecl __fpclassifyl (long double x){
270 unsigned short sw;
271 __asm__ ("fxam; fstsw %%ax;" : "=a" (sw): "t" (x));
272 return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
273 }
274
275 __CRT_INLINE int __cdecl __fpclassify (double x){
276 return __fpclassifyl((long double)x);
277 }
278
279 #define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \
280 : sizeof (x) == sizeof (double) ? __fpclassify (x) \
281 : __fpclassifyl (x))
282
283 /* 7.12.3.2 */
284 #define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)
285
286 /* 7.12.3.3 */
287 /* #define isinf(x) (fpclassify(x) == FP_INFINITE) */
288
289 /* we don't have fpclassify */
290 __CRT_INLINE int isinf (double d) {
291 int expon = 0;
292 double val = frexp (d, &expon);
293 if (expon == 1025) {
294 if (val == 0.5) {
295 return 1;
296 } else if (val == -0.5) {
297 return -1;
298 } else {
299 return 0;
300 }
301 } else {
302 return 0;
303 }
304 }
305
306 /* 7.12.3.4 */
307 /* We don't need to worry about truncation here:
308 A NaN stays a NaN. */
309
310 __CRT_INLINE int __cdecl __isnan (double _x)
311 {
312 unsigned short sw;
313 __asm__ ("fxam;"
314 "fstsw %%ax": "=a" (sw) : "t" (_x));
315 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
316 == FP_NAN;
317 }
318
319 __CRT_INLINE int __cdecl __isnanf (float _x)
320 {
321 unsigned short sw;
322 __asm__ ("fxam;"
323 "fstsw %%ax": "=a" (sw) : "t" (_x));
324 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
325 == FP_NAN;
326 }
327
328 __CRT_INLINE int __cdecl __isnanl (long double _x)
329 {
330 unsigned short sw;
331 __asm__ ("fxam;"
332 "fstsw %%ax": "=a" (sw) : "t" (_x));
333 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
334 == FP_NAN;
335 }
336
337
338 #define isnan(x) (sizeof (x) == sizeof (float) ? __isnanf (x) \
339 : sizeof (x) == sizeof (double) ? __isnan (x) \
340 : __isnanl (x))
341
342 /* 7.12.3.5 */
343 #define isnormal(x) (fpclassify(x) == FP_NORMAL)
344
345 /* 7.12.3.6 The signbit macro */
346 __CRT_INLINE int __cdecl __signbit (double x) {
347 unsigned short stw;
348 __asm__ ( "fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
349 return stw & 0x0200;
350 }
351
352 __CRT_INLINE int __cdecl __signbitf (float x) {
353 unsigned short stw;
354 __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
355 return stw & 0x0200;
356 }
357
358 __CRT_INLINE int __cdecl __signbitl (long double x) {
359 unsigned short stw;
360 __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
361 return stw & 0x0200;
362 }
363
364 #define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x) \
365 : sizeof (x) == sizeof (double) ? __signbit (x) \
366 : __signbitl (x))
367
368 extern double __cdecl exp2(double);
369 extern float __cdecl exp2f(float);
370 extern long double __cdecl exp2l(long double);
371
372 #define FP_ILOGB0 ((int)0x80000000)
373 #define FP_ILOGBNAN ((int)0x80000000)
374 extern int __cdecl ilogb (double);
375 extern int __cdecl ilogbf (float);
376 extern int __cdecl ilogbl (long double);
377
378 extern double __cdecl log1p(double);
379 extern float __cdecl log1pf(float);
380 extern long double __cdecl log1pl(long double);
381
382 extern double __cdecl log2 (double);
383 extern float __cdecl log2f (float);
384 extern long double __cdecl log2l (long double);
385
386 extern double __cdecl logb (double);
387 extern float __cdecl logbf (float);
388 extern long double __cdecl logbl (long double);
389
390 __CRT_INLINE double __cdecl logb (double x)
391 {
392 double res;
393 __asm__ ("fxtract\n\t"
394 "fstp %%st" : "=t" (res) : "0" (x));
395 return res;
396 }
397
398 __CRT_INLINE float __cdecl logbf (float x)
399 {
400 float res;
401 __asm__ ("fxtract\n\t"
402 "fstp %%st" : "=t" (res) : "0" (x));
403 return res;
404 }
405
406 __CRT_INLINE long double __cdecl logbl (long double x)
407 {
408 long double res;
409 __asm__ ("fxtract\n\t"
410 "fstp %%st" : "=t" (res) : "0" (x));
411 return res;
412 }
413
414 extern long double __cdecl modfl (long double, long double*);
415
416 /* 7.12.6.13 */
417 extern double __cdecl scalbn (double, int);
418 extern float __cdecl scalbnf (float, int);
419 extern long double __cdecl scalbnl (long double, int);
420
421 extern double __cdecl scalbln (double, long);
422 extern float __cdecl scalblnf (float, long);
423 extern long double __cdecl scalblnl (long double, long);
424
425 /* 7.12.7.1 */
426 /* Implementations adapted from Cephes versions */
427 extern double __cdecl cbrt (double);
428 extern float __cdecl cbrtf (float);
429 extern long double __cdecl cbrtl (long double);
430
431 __CRT_INLINE float __cdecl hypotf (float x, float y)
432 { return (float) hypot (x, y);}
433 extern long double __cdecl hypotl (long double, long double);
434
435 extern long double __cdecl powl (long double, long double);
436 extern long double __cdecl expl(long double);
437 extern long double expm1l(long double);
438 extern long double __cdecl coshl(long double);
439 extern long double __cdecl fabsl (long double);
440 extern long double __cdecl acosl(long double);
441 extern long double __cdecl asinl(long double);
442 extern long double __cdecl atanl(long double);
443 extern long double __cdecl atan2l(long double,long double);
444 extern long double __cdecl sinhl(long double);
445 extern long double __cdecl tanhl(long double);
446
447 /* 7.12.8.1 The erf functions */
448 extern double __cdecl erf (double);
449 extern float __cdecl erff (float);
450 /* TODO
451 extern long double __cdecl erfl (long double);
452 */
453
454 /* 7.12.8.2 The erfc functions */
455 extern double __cdecl erfc (double);
456 extern float __cdecl erfcf (float);
457 /* TODO
458 extern long double __cdecl erfcl (long double);
459 */
460
461 /* 7.12.8.3 The lgamma functions */
462 extern double __cdecl lgamma (double);
463 extern float __cdecl lgammaf (float);
464 extern long double __cdecl lgammal (long double);
465
466 /* 7.12.8.4 The tgamma functions */
467 extern double __cdecl tgamma (double);
468 extern float __cdecl tgammaf (float);
469 extern long double __cdecl tgammal (long double);
470
471 extern long double __cdecl ceill (long double);
472 extern long double __cdecl floorl (long double);
473 extern long double __cdecl frexpl(long double,int *);
474 extern long double __cdecl log10l(long double);
475 extern long double __cdecl logl(long double);
476 extern long double __cdecl cosl(long double);
477 extern long double __cdecl sinl(long double);
478 extern long double __cdecl tanl(long double);
479 extern long double sqrtl(long double);
480
481 /* 7.12.9.3 */
482 extern double __cdecl nearbyint ( double);
483 extern float __cdecl nearbyintf (float);
484 extern long double __cdecl nearbyintl (long double);
485
486 /* 7.12.9.4 */
487 /* round, using fpu control word settings */
488 __CRT_INLINE double __cdecl rint (double x)
489 {
490 double retval;
491 __asm__ ("frndint;": "=t" (retval) : "0" (x));
492 return retval;
493 }
494
495 __CRT_INLINE float __cdecl rintf (float x)
496 {
497 float retval;
498 __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
499 return retval;
500 }
501
502 __CRT_INLINE long double __cdecl rintl (long double x)
503 {
504 long double retval;
505 __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
506 return retval;
507 }
508
509 /* 7.12.9.5 */
510 __CRT_INLINE long __cdecl lrint (double x)
511 {
512 long retval;
513 __asm__ __volatile__ \
514 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); \
515 return retval;
516 }
517
518 __CRT_INLINE long __cdecl lrintf (float x)
519 {
520 long retval;
521 __asm__ __volatile__ \
522 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); \
523 return retval;
524 }
525
526 __CRT_INLINE long __cdecl lrintl (long double x)
527 {
528 long retval;
529 __asm__ __volatile__ \
530 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); \
531 return retval;
532 }
533
534 __CRT_INLINE long long __cdecl llrint (double x)
535 {
536 long long retval;
537 __asm__ __volatile__ \
538 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); \
539 return retval;
540 }
541
542 __CRT_INLINE long long __cdecl llrintf (float x)
543 {
544 long long retval;
545 __asm__ __volatile__ \
546 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); \
547 return retval;
548 }
549
550 __CRT_INLINE long long __cdecl llrintl (long double x)
551 {
552 long long retval;
553 __asm__ __volatile__ \
554 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); \
555 return retval;
556 }
557
558 /* 7.12.9.6 */
559 /* round away from zero, regardless of fpu control word settings */
560 extern double __cdecl round (double);
561 extern float __cdecl roundf (float);
562 extern long double __cdecl roundl (long double);
563
564 /* 7.12.9.7 */
565 extern long __cdecl lround (double);
566 extern long __cdecl lroundf (float);
567 extern long __cdecl lroundl (long double);
568
569 extern long long __cdecl llround (double);
570 extern long long __cdecl llroundf (float);
571 extern long long __cdecl llroundl (long double);
572
573 /* 7.12.9.8 */
574 /* round towards zero, regardless of fpu control word settings */
575 extern double __cdecl trunc (double);
576 extern float __cdecl truncf (float);
577 extern long double __cdecl truncl (long double);
578
579 extern long double __cdecl fmodl (long double, long double);
580
581 /* 7.12.10.2 */
582 extern double __cdecl remainder (double, double);
583 extern float __cdecl remainderf (float, float);
584 extern long double __cdecl remainderl (long double, long double);
585
586 /* 7.12.10.3 */
587 extern double __cdecl remquo(double, double, int *);
588 extern float __cdecl remquof(float, float, int *);
589 extern long double __cdecl remquol(long double, long double, int *);
590
591 /* 7.12.11.1 */
592 extern double __cdecl copysign (double, double); /* in libmoldname.a */
593 extern float __cdecl copysignf (float, float);
594 extern long double __cdecl copysignl (long double, long double);
595
596 /* 7.12.11.2 Return a NaN */
597 extern double __cdecl nan(const char *tagp);
598 extern float __cdecl nanf(const char *tagp);
599 extern long double __cdecl nanl(const char *tagp);
600
601 #ifndef __STRICT_ANSI__
602 #define _nan() nan("")
603 #define _nanf() nanf("")
604 #define _nanl() nanl("")
605 #endif
606
607 /* 7.12.11.3 */
608 extern double __cdecl nextafter (double, double); /* in libmoldname.a */
609 extern float __cdecl nextafterf (float, float);
610 extern long double __cdecl nextafterl (long double, long double);
611
612 /* 7.12.11.4 The nexttoward functions: TODO */
613
614 /* 7.12.12.1 */
615 /* x > y ? (x - y) : 0.0 */
616 extern double __cdecl fdim (double x, double y);
617 extern float __cdecl fdimf (float x, float y);
618 extern long double __cdecl fdiml (long double x, long double y);
619
620 /* fmax and fmin.
621 NaN arguments are treated as missing data: if one argument is a NaN
622 and the other numeric, then these functions choose the numeric
623 value. */
624
625 /* 7.12.12.2 */
626 extern double __cdecl fmax (double, double);
627 extern float __cdecl fmaxf (float, float);
628 extern long double __cdecl fmaxl (long double, long double);
629
630 /* 7.12.12.3 */
631 extern double __cdecl fmin (double, double);
632 extern float __cdecl fminf (float, float);
633 extern long double __cdecl fminl (long double, long double);
634
635 /* 7.12.13.1 */
636 /* return x * y + z as a ternary op */
637 extern double __cdecl fma (double, double, double);
638 extern float __cdecl fmaf (float, float, float);
639 extern long double __cdecl fmal (long double, long double, long double);
640
641
642 /* 7.12.14 */
643 /*
644 * With these functions, comparisons involving quiet NaNs set the FP
645 * condition code to "unordered". The IEEE floating-point spec
646 * dictates that the result of floating-point comparisons should be
647 * false whenever a NaN is involved, with the exception of the != op,
648 * which always returns true: yes, (NaN != NaN) is true).
649 */
650
651 #if __GNUC__ >= 3
652
653 #define isgreater(x, y) __builtin_isgreater(x, y)
654 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
655 #define isless(x, y) __builtin_isless(x, y)
656 #define islessequal(x, y) __builtin_islessequal(x, y)
657 #define islessgreater(x, y) __builtin_islessgreater(x, y)
658 #define isunordered(x, y) __builtin_isunordered(x, y)
659
660 #else
661 /* helper */
662 __CRT_INLINE int __cdecl
663 __fp_unordered_compare (long double x, long double y){
664 unsigned short retval;
665 __asm__ ("fucom %%st(1);"
666 "fnstsw;": "=a" (retval) : "t" (x), "u" (y));
667 return retval;
668 }
669
670 #define isgreater(x, y) ((__fp_unordered_compare(x, y) \
671 & 0x4500) == 0)
672 #define isless(x, y) ((__fp_unordered_compare (y, x) \
673 & 0x4500) == 0)
674 #define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \
675 & FP_INFINITE) == 0)
676 #define islessequal(x, y) ((__fp_unordered_compare(y, x) \
677 & FP_INFINITE) == 0)
678 #define islessgreater(x, y) ((__fp_unordered_compare(x, y) \
679 & FP_SUBNORMAL) == 0)
680 #define isunordered(x, y) ((__fp_unordered_compare(x, y) \
681 & 0x4500) == 0x4500)
682
683 #endif
684
685
686 #endif /* __STDC_VERSION__ >= 199901L */
687 #endif /* __NO_ISOCEXT */
688
689 #ifdef __cplusplus
690 }
691 extern "C++" {
692 template<class _Ty> inline _Ty _Pow_int(_Ty _X,int _Y) {
693 unsigned int _N;
694 if(_Y >= 0) _N = (unsigned int)_Y;
695 else _N = (unsigned int)(-_Y);
696 for(_Ty _Z = _Ty(1);;_X *= _X) {
697 if((_N & 1)!=0) _Z *= _X;
698 if((_N >>= 1)==0) return (_Y < 0 ? _Ty(1) / _Z : _Z);
699 }
700 }
701 }
702 #endif
703
704 #pragma pack(pop)
705
706 #if !defined(__STRICT_ANSI__) && !defined(_MATH_DEFINES_DEFINED)
707 #define _MATH_DEFINES_DEFINED
708
709 #define M_E 2.71828182845904523536
710 #define M_LOG2E 1.44269504088896340736
711 #define M_LOG10E 0.434294481903251827651
712 #define M_LN2 0.693147180559945309417
713 #define M_LN10 2.30258509299404568402
714 #define M_PI 3.14159265358979323846
715 #define M_PI_2 1.57079632679489661923
716 #define M_PI_4 0.785398163397448309616
717 #define M_1_PI 0.318309886183790671538
718 #define M_2_PI 0.636619772367581343076
719 #define M_2_SQRTPI 1.12837916709551257390
720 #define M_SQRT2 1.41421356237309504880
721 #define M_SQRT1_2 0.707106781186547524401
722 #endif
723
724 #ifndef __MINGW_FPCLASS_DEFINED
725 #define __MINGW_FPCLASS_DEFINED 1
726 #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
727 #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
728 #define _FPCLASS_NINF 0x0004 /* Negative Infinity */
729 #define _FPCLASS_NN 0x0008 /* Negative Normal */
730 #define _FPCLASS_ND 0x0010 /* Negative Denormal */
731 #define _FPCLASS_NZ 0x0020 /* Negative Zero */
732 #define _FPCLASS_PZ 0x0040 /* Positive Zero */
733 #define _FPCLASS_PD 0x0080 /* Positive Denormal */
734 #define _FPCLASS_PN 0x0100 /* Positive Normal */
735 #define _FPCLASS_PINF 0x0200 /* Positive Infinity */
736 #endif /* __MINGW_FPCLASS_DEFINED */
737
738 /* 7.12.14 */
739 /*
740 * With these functions, comparisons involving quiet NaNs set the FP
741 * condition code to "unordered". The IEEE floating-point spec
742 * dictates that the result of floating-point comparisons should be
743 * false whenever a NaN is involved, with the exception of the != op,
744 * which always returns true: yes, (NaN != NaN) is true).
745 */
746
747 #if __GNUC__ >= 3
748
749 #define isgreater(x, y) __builtin_isgreater(x, y)
750 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
751 #define isless(x, y) __builtin_isless(x, y)
752 #define islessequal(x, y) __builtin_islessequal(x, y)
753 #define islessgreater(x, y) __builtin_islessgreater(x, y)
754 #define isunordered(x, y) __builtin_isunordered(x, y)
755
756 #else
757 /* helper */
758 __CRT_INLINE int __cdecl
759 __fp_unordered_compare (long double x, long double y){
760 unsigned short retval;
761 __asm__ ("fucom %%st(1);"
762 "fnstsw;": "=a" (retval) : "t" (x), "u" (y));
763 return retval;
764 }
765
766 #define isgreater(x, y) ((__fp_unordered_compare(x, y) \
767 & 0x4500) == 0)
768 #define isless(x, y) ((__fp_unordered_compare (y, x) \
769 & 0x4500) == 0)
770 #define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \
771 & FP_INFINITE) == 0)
772 #define islessequal(x, y) ((__fp_unordered_compare(y, x) \
773 & FP_INFINITE) == 0)
774 #define islessgreater(x, y) ((__fp_unordered_compare(x, y) \
775 & FP_SUBNORMAL) == 0)
776 #define isunordered(x, y) ((__fp_unordered_compare(x, y) \
777 & 0x4500) == 0x4500)
778
779 #endif
780
781 #endif /* !_INC_MATH */