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