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