OSDN Git Service

Redo the filters based on assumptions discussed in mingw-dvlpr list.
[mingw/mingw-org-wsl.git] / include / math.h
1 /**
2  * @file math.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _MATH_H_
25 #define _MATH_H_
26 #pragma GCC system_header
27
28 /* All the headers include this file. */
29 #include <_mingw.h>
30
31 /*
32  * Types for the _exception structure.
33  */
34
35 #define _DOMAIN         1       /* domain error in argument */
36 #define _SING           2       /* singularity */
37 #define _OVERFLOW       3       /* range overflow */
38 #define _UNDERFLOW      4       /* range underflow */
39 #define _TLOSS          5       /* total loss of precision */
40 #define _PLOSS          6       /* partial loss of precision */
41
42 /*
43  * Exception types with non-ANSI names for compatibility.
44  */
45
46 #ifndef __STRICT_ANSI__
47 #ifndef _NO_OLDNAMES
48
49 #define DOMAIN          _DOMAIN
50 #define SING            _SING
51 #define OVERFLOW        _OVERFLOW
52 #define UNDERFLOW       _UNDERFLOW
53 #define TLOSS           _TLOSS
54 #define PLOSS           _PLOSS
55
56 #endif  /* Not _NO_OLDNAMES */
57 #endif  /* Not __STRICT_ANSI__ */
58
59
60 /* Traditional/XOPEN math constants (double precison) */
61 #ifndef __STRICT_ANSI__
62 #define M_E             2.7182818284590452354
63 #define M_LOG2E         1.4426950408889634074
64 #define M_LOG10E        0.43429448190325182765
65 #define M_LN2           0.69314718055994530942
66 #define M_LN10          2.30258509299404568402
67 #define M_PI            3.14159265358979323846
68 #define M_PI_2          1.57079632679489661923
69 #define M_PI_4          0.78539816339744830962
70 #define M_1_PI          0.31830988618379067154
71 #define M_2_PI          0.63661977236758134308
72 #define M_2_SQRTPI      1.12837916709551257390
73 #define M_SQRT2         1.41421356237309504880
74 #define M_SQRT1_2       0.70710678118654752440
75 #endif
76
77 /* These are also defined in Mingw float.h; needed here as well to work 
78    around GCC build issues.  */
79 #ifndef __STRICT_ANSI__
80 #ifndef __MINGW_FPCLASS_DEFINED
81 #define __MINGW_FPCLASS_DEFINED 1
82 /* IEEE 754 classication */
83 #define _FPCLASS_SNAN   0x0001  /* Signaling "Not a Number" */
84 #define _FPCLASS_QNAN   0x0002  /* Quiet "Not a Number" */
85 #define _FPCLASS_NINF   0x0004  /* Negative Infinity */
86 #define _FPCLASS_NN     0x0008  /* Negative Normal */
87 #define _FPCLASS_ND     0x0010  /* Negative Denormal */
88 #define _FPCLASS_NZ     0x0020  /* Negative Zero */
89 #define _FPCLASS_PZ     0x0040  /* Positive Zero */
90 #define _FPCLASS_PD     0x0080  /* Positive Denormal */
91 #define _FPCLASS_PN     0x0100  /* Positive Normal */
92 #define _FPCLASS_PINF   0x0200  /* Positive Infinity */
93 #endif /* __MINGW_FPCLASS_DEFINED */
94 #endif  /* Not __STRICT_ANSI__ */
95
96 #ifndef RC_INVOKED
97
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101
102 /*
103  * HUGE_VAL is returned by strtod when the value would overflow the
104  * representation of 'double'. There are other uses as well.
105  *
106  * __imp__HUGE is a pointer to the actual variable _HUGE in
107  * MSVCRT.DLL. If we used _HUGE directly we would get a pointer
108  * to a thunk function.
109  */
110
111 #define HUGE_VAL __builtin_huge_val()
112
113 struct _exception
114 {
115         int     type;
116         char    *name;
117         double  arg1;
118         double  arg2;
119         double  retval;
120 };
121
122 _CRTIMP double __cdecl sin (double);
123 _CRTIMP double __cdecl cos (double);
124 _CRTIMP double __cdecl tan (double);
125 _CRTIMP double __cdecl sinh (double);
126 _CRTIMP double __cdecl cosh (double);
127 _CRTIMP double __cdecl tanh (double);
128 _CRTIMP double __cdecl asin (double);
129 _CRTIMP double __cdecl acos (double);
130 _CRTIMP double __cdecl atan (double);
131 _CRTIMP double __cdecl atan2 (double, double);
132 _CRTIMP double __cdecl exp (double);
133 _CRTIMP double __cdecl log (double);
134 _CRTIMP double __cdecl log10 (double);
135 _CRTIMP double __cdecl pow (double, double);
136 _CRTIMP double __cdecl sqrt (double);
137 _CRTIMP double __cdecl ceil (double);
138 _CRTIMP double __cdecl floor (double);
139 _CRTIMP double __cdecl fabs (double);
140 _CRTIMP double __cdecl ldexp (double, int);
141 _CRTIMP double __cdecl frexp (double, int*);
142 _CRTIMP double __cdecl modf (double, double*);
143 _CRTIMP double __cdecl fmod (double, double);
144
145 /* Excess precision when using a 64-bit mantissa for FPU math ops can
146    cause unexpected results with some of the MSVCRT math functions.  For
147    example, unless the function return value is stored (truncating to
148    53-bit mantissa), calls to pow with both x and y as integral values
149    sometimes produce a non-integral result.
150    One workaround is to reset the FPU env to 53-bit mantissa
151    by a call to fesetenv (FE_PC53_ENV).  Amother is to force storage
152    of the return value of individual math functions using wrappers.
153    NB, using these wrappers will disable builtin math functions and
154    hence disable the folding of function results at compile time when
155    arguments are constant.  */
156
157 #if 0
158 #define __DEFINE_FLOAT_STORE_MATHFN_D1(fn1)     \
159 static __inline__ double                        \
160 __float_store_ ## fn1 (double x)                \
161 {                                               \
162    __volatile__ double res = (fn1) (x);         \
163   return res;                                   \
164 }
165
166 #define __DEFINE_FLOAT_STORE_MATHFN_D2(fn2)     \
167 static __inline__ double                        \
168 __float_store_ ## fn2 (double x, double y)      \
169 {                                               \
170   __volatile__ double res = (fn2) (x, y);       \
171   return res;                                   \
172 }
173 #endif
174
175 /* For example, here is how to force the result of the pow function
176    to be stored:   */
177 #if 0
178 #undef pow
179 /* Define the ___float_store_pow function and use it instead of pow().  */
180 __DEFINE_FLOAT_STORE_MATHFN_D2 (pow)
181 #define pow __float_store_pow
182 #endif
183
184 #ifndef __STRICT_ANSI__
185
186 /* Complex number (for _cabs). This is the MS version. The ISO
187    C99 counterpart _Complex is an intrinsic type in GCC and
188    'complex' is defined as a macro.  See complex.h  */
189 struct _complex
190 {
191         double  x;      /* Real part */
192         double  y;      /* Imaginary part */
193 };
194
195 _CRTIMP double __cdecl _cabs (struct _complex);
196
197 _CRTIMP double __cdecl _hypot (double, double);
198 _CRTIMP double __cdecl _j0 (double);
199 _CRTIMP double __cdecl _j1 (double);
200 _CRTIMP double __cdecl _jn (int, double);
201 _CRTIMP double __cdecl _y0 (double);
202 _CRTIMP double __cdecl _y1 (double);
203 _CRTIMP double __cdecl _yn (int, double);
204 _CRTIMP int __cdecl _matherr (struct _exception *);
205
206 /* These are also declared in Mingw float.h; needed here as well to work 
207    around GCC build issues.  */
208 /* BEGIN FLOAT.H COPY */
209 /*
210  * IEEE recommended functions
211  */
212
213 _CRTIMP double __cdecl _chgsign (double);
214 _CRTIMP double __cdecl _copysign (double, double);
215 _CRTIMP double __cdecl _logb (double);
216 _CRTIMP double __cdecl _nextafter (double, double);
217 _CRTIMP double __cdecl _scalb (double, long);
218
219 _CRTIMP int __cdecl _finite (double);
220 _CRTIMP int __cdecl _fpclass (double);
221 _CRTIMP int __cdecl _isnan (double);
222
223 /* END FLOAT.H COPY */
224
225
226 /*
227  * Non-underscored versions of non-ANSI functions.
228  * These reside in liboldnames.a.
229  */
230
231 #if !defined (_NO_OLDNAMES)
232
233 _CRTIMP double __cdecl j0 (double);
234 _CRTIMP double __cdecl j1 (double);
235 _CRTIMP double __cdecl jn (int, double);
236 _CRTIMP double __cdecl y0 (double);
237 _CRTIMP double __cdecl y1 (double);
238 _CRTIMP double __cdecl yn (int, double);
239
240 _CRTIMP double __cdecl chgsign (double);
241 /*
242  * scalb() is a GCC built-in.
243  * Exclude this _scalb() stub; the semantics are incompatible
244  * with the built-in implementation.
245  *
246 _CRTIMP double __cdecl scalb (double, long);
247  *
248  */
249 _CRTIMP int __cdecl finite (double);
250 _CRTIMP int __cdecl fpclass (double);
251
252 #define FP_SNAN    _FPCLASS_SNAN
253 #define FP_QNAN    _FPCLASS_QNAN
254 #define FP_NINF    _FPCLASS_NINF
255 #define FP_PINF    _FPCLASS_PINF
256 #define FP_NDENORM _FPCLASS_ND
257 #define FP_PDENORM _FPCLASS_PD
258 #define FP_NZERO   _FPCLASS_NZ
259 #define FP_PZERO   _FPCLASS_PZ
260 #define FP_NNORM   _FPCLASS_NN
261 #define FP_PNORM   _FPCLASS_PN
262
263 #endif /* Not _NO_OLDNAMES */
264
265 /* This require msvcr70.dll or higher. */ 
266 #if __MSVCRT_VERSION__ >= 0x0700
267 _CRTIMP int __cdecl _set_SSE2_enable (int);
268 #endif /* __MSVCRT_VERSION__ >= 0x0700 */
269
270
271 #endif /* __STRICT_ANSI__ */
272
273
274 #ifndef __NO_ISOCEXT
275 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
276         || !defined __STRICT_ANSI__ || defined __cplusplus
277
278 #if __MINGW_GNUC_PREREQ(3, 3)
279 #define HUGE_VALF       __builtin_huge_valf()
280 #define HUGE_VALL       __builtin_huge_vall()
281 #define INFINITY        __builtin_inf()
282 #define NAN             __builtin_nan("")
283 #else
284 extern const float __INFF;
285 #define HUGE_VALF __INFF
286 extern const long double  __INFL;
287 #define HUGE_VALL __INFL
288 #define INFINITY HUGE_VALF
289 extern const double __QNAN;
290 #define NAN __QNAN
291 #endif /* __MINGW_GNUC_PREREQ(3, 3) */
292
293 /* Use the compiler's builtin define for FLT_EVAL_METHOD to
294    set float_t and double_t.  */
295 #if defined(__FLT_EVAL_METHOD__)  
296 # if ( __FLT_EVAL_METHOD__== 0)
297 typedef float float_t;
298 typedef double double_t;
299 # elif (__FLT_EVAL_METHOD__ == 1)
300 typedef double float_t;
301 typedef double double_t;
302 # elif (__FLT_EVAL_METHOD__ == 2)
303 typedef long double float_t;
304 typedef long double double_t;
305 #endif
306 #else /* ix87 FPU default */
307 typedef long double float_t;
308 typedef long double double_t;
309 #endif
310
311 /* 7.12.3.1 */
312 /*
313    Return values for fpclassify.
314    These are based on Intel x87 fpu condition codes
315    in the high byte of status word and differ from
316    the return values for MS IEEE 754 extension _fpclass()
317 */
318 #define FP_NAN          0x0100
319 #define FP_NORMAL       0x0400
320 #define FP_INFINITE     (FP_NAN | FP_NORMAL)
321 #define FP_ZERO         0x4000
322 #define FP_SUBNORMAL    (FP_NORMAL | FP_ZERO)
323 /* 0x0200 is signbit mask */
324
325
326 /*
327   We can't inline float or double, because we want to ensure truncation
328   to semantic type before classification. 
329   (A normal long double value might become subnormal when 
330   converted to double, and zero when converted to float.)
331 */
332
333 extern int __cdecl __fpclassifyf (float);
334 extern int __cdecl __fpclassify (double);
335 extern int __cdecl __fpclassifyl (long double);
336
337 #ifndef __NO_INLINE__
338 __CRT_INLINE int __cdecl __fpclassifyl (long double x){
339   unsigned short sw;
340   __asm__ ("fxam; fstsw %%ax;" : "=a" (sw): "t" (x));
341   return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
342 }
343 #endif
344
345 #define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x)   \
346                        : sizeof (x) == sizeof (double) ? __fpclassify (x) \
347                        : __fpclassifyl (x))
348
349 /* 7.12.3.2 */
350 #define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)
351
352 /* 7.12.3.3 */
353 #define isinf(x) (fpclassify(x) == FP_INFINITE)
354
355 /* 7.12.3.4 */
356 /* We don't need to worry about truncation here:
357    A NaN stays a NaN. */
358 extern int __cdecl __isnan (double);
359 extern int __cdecl __isnanf (float);
360 extern int __cdecl __isnanl (long double);
361 #ifndef __NO_INLINE__
362 __CRT_INLINE int __cdecl __isnan (double _x)
363 {
364   unsigned short sw;
365   __asm__ ("fxam;"
366            "fstsw %%ax": "=a" (sw) : "t" (_x));
367   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
368     == FP_NAN;
369 }
370
371 __CRT_INLINE int __cdecl __isnanf (float _x)
372 {
373   unsigned short sw;
374   __asm__ ("fxam;"
375             "fstsw %%ax": "=a" (sw) : "t" (_x));
376   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
377     == FP_NAN;
378 }
379
380 __CRT_INLINE int __cdecl __isnanl (long double _x)
381 {
382   unsigned short sw;
383   __asm__ ("fxam;"
384             "fstsw %%ax": "=a" (sw) : "t" (_x));
385   return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
386     == FP_NAN;
387 }
388 #endif
389
390 #define isnan(x) (sizeof (x) == sizeof (float) ? __isnanf (x)   \
391                   : sizeof (x) == sizeof (double) ? __isnan (x) \
392                   : __isnanl (x))
393
394 /* 7.12.3.5 */
395 #define isnormal(x) (fpclassify(x) == FP_NORMAL)
396
397 /* 7.12.3.6 The signbit macro */
398 extern int __cdecl __signbit (double);
399 extern int __cdecl __signbitf (float);
400 extern int __cdecl __signbitl (long double);
401 #ifndef __NO_INLINE__
402 __CRT_INLINE int __cdecl __signbit (double x) {
403   unsigned short stw;
404   __asm__ ( "fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
405   return (stw & 0x0200) != 0;
406 }
407
408 __CRT_INLINE int __cdecl __signbitf (float x) {
409   unsigned short stw;
410   __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
411   return (stw & 0x0200) != 0;
412 }
413
414 __CRT_INLINE int __cdecl __signbitl (long double x) {
415   unsigned short stw;
416   __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
417   return (stw & 0x0200) != 0;
418 }
419 #endif
420
421 #define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x)       \
422                     : sizeof (x) == sizeof (double) ? __signbit (x)     \
423                     : __signbitl (x))
424
425 /* 7.12.4 Trigonometric functions: Double in C89 */
426 extern float __cdecl sinf (float);
427 extern long double __cdecl sinl (long double);
428
429 extern float __cdecl cosf (float);
430 extern long double __cdecl cosl (long double);
431
432 extern float __cdecl tanf (float);
433 extern long double __cdecl tanl (long double);
434
435 extern float __cdecl asinf (float);
436 extern long double __cdecl asinl (long double);
437
438 extern float __cdecl acosf (float);
439 extern long double __cdecl acosl (long double);
440
441 extern float __cdecl atanf (float);
442 extern long double __cdecl atanl (long double);
443
444 extern float __cdecl atan2f (float, float);
445 extern long double __cdecl atan2l (long double, long double);
446
447 /* 7.12.5 Hyperbolic functions: Double in C89  */
448 extern float __cdecl sinhf (float);
449 #ifndef __NO_INLINE__
450 __CRT_INLINE float __cdecl sinhf (float x)
451   {return (float) sinh (x);}
452 #endif
453 extern long double __cdecl sinhl (long double);
454
455 extern float __cdecl coshf (float);
456 #ifndef __NO_INLINE__
457 __CRT_INLINE float __cdecl coshf (float x)
458   {return (float) cosh (x);}
459 #endif
460 extern long double __cdecl coshl (long double);
461
462 extern float __cdecl tanhf (float);
463 #ifndef __NO_INLINE__
464 __CRT_INLINE float __cdecl tanhf (float x)
465   {return (float) tanh (x);}
466 #endif
467 extern long double __cdecl tanhl (long double);
468
469 /* Inverse hyperbolic trig functions  */ 
470 /* 7.12.5.1 */
471 extern double __cdecl acosh (double);
472 extern float __cdecl acoshf (float);
473 extern long double __cdecl acoshl (long double);
474
475 /* 7.12.5.2 */
476 extern double __cdecl asinh (double);
477 extern float __cdecl asinhf (float);
478 extern long double __cdecl asinhl (long double);
479
480 /* 7.12.5.3 */
481 extern double __cdecl atanh (double);
482 extern float __cdecl atanhf  (float);
483 extern long double __cdecl atanhl (long double);
484
485 /* Exponentials and logarithms  */
486 /* 7.12.6.1 Double in C89 */
487 extern float __cdecl expf (float);
488 #ifndef __NO_INLINE__
489 __CRT_INLINE float __cdecl expf (float x)
490   {return (float) exp (x);}
491 #endif
492 extern long double __cdecl expl (long double);
493
494 /* 7.12.6.2 */
495 extern double __cdecl exp2(double);
496 extern float __cdecl exp2f(float);
497 extern long double __cdecl exp2l(long double);
498
499 /* 7.12.6.3 The expm1 functions */
500 /* TODO: These could be inlined */
501 extern double __cdecl expm1(double);
502 extern float __cdecl expm1f(float);
503 extern long double __cdecl expm1l(long double);
504
505 /* 7.12.6.4 Double in C89 */
506 extern float __cdecl frexpf (float, int*);
507 #ifndef __NO_INLINE__
508 __CRT_INLINE float __cdecl frexpf (float x, int* expn)
509   {return (float) frexp (x, expn);}
510 #endif
511 extern long double __cdecl frexpl (long double, int*);
512
513 /* 7.12.6.5 */
514 #define FP_ILOGB0 ((int)0x80000000)
515 #define FP_ILOGBNAN ((int)0x80000000)
516 extern int __cdecl ilogb (double);
517 extern int __cdecl ilogbf (float);
518 extern int __cdecl ilogbl (long double);
519
520 /* 7.12.6.6  Double in C89 */
521 extern float __cdecl ldexpf (float, int);
522 #ifndef __NO_INLINE__
523 __CRT_INLINE float __cdecl ldexpf (float x, int expn)
524   {return (float) ldexp (x, expn);}
525 #endif
526 extern long double __cdecl ldexpl (long double, int);
527
528 /* 7.12.6.7 Double in C89 */
529 extern float __cdecl logf (float);
530 extern long double __cdecl logl (long double);
531
532 /* 7.12.6.8 Double in C89 */
533 extern float __cdecl log10f (float);
534 extern long double __cdecl log10l (long double);
535
536 /* 7.12.6.9 */
537 extern double __cdecl log1p(double);
538 extern float __cdecl log1pf(float);
539 extern long double __cdecl log1pl(long double);
540
541 /* 7.12.6.10 */
542 extern double __cdecl log2 (double);
543 extern float __cdecl log2f (float);
544 extern long double __cdecl log2l (long double);
545
546 /* 7.12.6.11 */
547 extern double __cdecl logb (double);
548 extern float __cdecl logbf (float);
549 extern long double __cdecl logbl (long double);
550
551 /* Inline versions.  GCC-4.0+ can do a better fast-math optimization
552    with __builtins. */ 
553 #ifndef __NO_INLINE__
554 #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ )
555 __CRT_INLINE double __cdecl logb (double x)
556 {
557   double res;
558   __asm__ ("fxtract\n\t"
559        "fstp    %%st" : "=t" (res) : "0" (x));
560   return res;
561 }
562
563 __CRT_INLINE float __cdecl logbf (float x)
564 {
565   float res;
566   __asm__ ("fxtract\n\t"
567        "fstp    %%st" : "=t" (res) : "0" (x));
568   return res;
569 }
570
571 __CRT_INLINE long double __cdecl logbl (long double x)
572 {
573   long double res;
574   __asm__ ("fxtract\n\t"
575        "fstp    %%st" : "=t" (res) : "0" (x));
576   return res;
577 }
578 #endif /* !defined __FAST_MATH__ || !__MINGW_GNUC_PREREQ (4, 0) */
579 #endif /* !defined __NO_INLINE__ */
580
581 /* 7.12.6.12  Double in C89 */
582 extern float __cdecl modff (float, float*);
583 extern long double __cdecl modfl (long double, long double*);
584
585 /* 7.12.6.13 */
586 extern double __cdecl scalbn (double, int);
587 extern float __cdecl scalbnf (float, int);
588 extern long double __cdecl scalbnl (long double, int);
589
590 extern double __cdecl scalbln (double, long);
591 extern float __cdecl scalblnf (float, long);
592 extern long double __cdecl scalblnl (long double, long);
593
594 /* 7.12.7.1 */
595 /* Implementations adapted from Cephes versions */ 
596 extern double __cdecl cbrt (double);
597 extern float __cdecl cbrtf (float);
598 extern long double __cdecl cbrtl (long double);
599
600 /* 7.12.7.2 The fabs functions: Double in C89 */
601 extern  float __cdecl fabsf (float x);
602 extern long double __cdecl fabsl (long double x);
603
604 /* 7.12.7.3  */
605 extern double __cdecl hypot (double, double); /* in libmoldname.a */
606 extern float __cdecl hypotf (float, float);
607 #ifndef __NO_INLINE__
608 __CRT_INLINE float __cdecl hypotf (float x, float y)
609   { return (float) hypot (x, y);}
610 #endif
611 extern long double __cdecl hypotl (long double, long double);
612
613 /* 7.12.7.4 The pow functions. Double in C89 */
614 extern float __cdecl powf (float, float);
615 #ifndef __NO_INLINE__
616 __CRT_INLINE float __cdecl powf (float x, float y)
617   {return (float) pow (x, y);}
618 #endif
619 extern long double __cdecl powl (long double, long double);
620
621 /* 7.12.7.5 The sqrt functions. Double in C89. */
622 extern float __cdecl sqrtf (float);
623 extern long double __cdecl sqrtl (long double);
624
625 /* 7.12.8.1 The erf functions  */
626 extern double __cdecl erf (double);
627 extern float __cdecl erff (float);
628 extern long double __cdecl erfl (long double);
629
630 /* 7.12.8.2 The erfc functions  */
631 extern double __cdecl erfc (double);
632 extern float __cdecl erfcf (float);
633 extern long double __cdecl erfcl (long double);
634
635 /* 7.12.8.3 The lgamma functions */
636 extern double __cdecl lgamma (double);
637 extern float __cdecl lgammaf (float);
638 extern long double __cdecl lgammal (long double);
639
640 /* 7.12.8.4 The tgamma functions */
641 extern double __cdecl tgamma (double);
642 extern float __cdecl tgammaf (float);
643 extern long double __cdecl tgammal (long double);
644
645 /* 7.12.9.1 Double in C89 */
646 extern float __cdecl ceilf (float);
647 extern long double __cdecl ceill (long double);
648
649 /* 7.12.9.2 Double in C89 */
650 extern float __cdecl floorf (float);
651 extern long double __cdecl floorl (long double);
652
653 /* 7.12.9.3 */
654 extern double __cdecl nearbyint ( double);
655 extern float __cdecl nearbyintf (float);
656 extern long double __cdecl nearbyintl (long double);
657
658 /* 7.12.9.4 */
659 /* round, using fpu control word settings */
660 extern double __cdecl rint (double);
661 extern float __cdecl rintf (float);
662 extern long double __cdecl rintl (long double);
663
664 /* 7.12.9.5 */
665 extern long __cdecl lrint (double);
666 extern long __cdecl lrintf (float);
667 extern long __cdecl lrintl (long double);
668
669 extern long long __cdecl llrint (double);
670 extern long long __cdecl llrintf (float);
671 extern long long __cdecl llrintl (long double);
672
673 /* Inline versions of above. 
674    GCC 4.0+ can do a better fast-math job with __builtins. */
675 #ifndef __NO_INLINE__
676 #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ )
677 __CRT_INLINE double __cdecl rint (double x)
678 {
679   double retval;
680   __asm__ ("frndint;": "=t" (retval) : "0" (x));
681   return retval;
682 }
683
684 __CRT_INLINE float __cdecl rintf (float x)
685 {
686   float retval;
687   __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
688   return retval;
689 }
690
691 __CRT_INLINE long double __cdecl rintl (long double x)
692 {
693   long double retval;
694   __asm__ ("frndint;" : "=t" (retval) : "0" (x) );
695   return retval;
696 }
697
698 __CRT_INLINE long __cdecl lrint (double x) 
699 {
700   long retval;  
701   __asm__ __volatile__
702     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
703   return retval;
704 }
705
706 __CRT_INLINE long __cdecl lrintf (float x) 
707 {
708   long retval;
709   __asm__ __volatile__
710     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
711   return retval;
712 }
713
714 __CRT_INLINE long __cdecl lrintl (long double x) 
715 {
716   long retval;
717   __asm__ __volatile__
718     ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
719   return retval;
720 }
721
722 __CRT_INLINE long long __cdecl llrint (double x)
723 {
724   long long retval;
725   __asm__ __volatile__
726     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
727   return retval;
728 }
729
730 __CRT_INLINE long long __cdecl llrintf (float x)
731 {
732   long long retval;
733   __asm__ __volatile__
734     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
735   return retval;
736 }
737
738 __CRT_INLINE long long __cdecl llrintl (long double x) 
739 {
740   long long retval;
741   __asm__ __volatile__
742     ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
743   return retval;
744 }
745 #endif /* !__FAST_MATH__ || !__MINGW_GNUC_PREREQ (4,0)  */
746 #endif /* !defined __NO_INLINE */
747
748 /* 7.12.9.6 */
749 /* round away from zero, regardless of fpu control word settings */
750 extern double __cdecl round (double);
751 extern float __cdecl roundf (float);
752 extern long double __cdecl roundl (long double);
753
754 /* 7.12.9.7  */
755 extern long __cdecl lround (double);
756 extern long __cdecl lroundf (float);
757 extern long __cdecl lroundl (long double);
758
759 extern long long __cdecl llround (double);
760 extern long long __cdecl llroundf (float);
761 extern long long __cdecl llroundl (long double);
762
763 /* 7.12.9.8 */
764 /* round towards zero, regardless of fpu control word settings */
765 extern double __cdecl trunc (double);
766 extern float __cdecl truncf (float);
767 extern long double __cdecl truncl (long double);
768
769 /* 7.12.10.1 Double in C89 */
770 extern float __cdecl fmodf (float, float);
771 extern long double __cdecl fmodl (long double, long double);
772
773 /* 7.12.10.2 */ 
774 extern double __cdecl remainder (double, double);
775 extern float __cdecl remainderf (float, float);
776 extern long double __cdecl remainderl (long double, long double);
777
778 /* 7.12.10.3 */
779 extern double __cdecl remquo(double, double, int *);
780 extern float __cdecl remquof(float, float, int *);
781 extern long double __cdecl remquol(long double, long double, int *);
782
783 /* 7.12.11.1 */
784 extern double __cdecl copysign (double, double); /* in libmoldname.a */
785 extern float __cdecl copysignf (float, float);
786 extern long double __cdecl copysignl (long double, long double);
787
788 /* 7.12.11.2 Return a NaN */
789 extern double __cdecl nan(const char *tagp);
790 extern float __cdecl nanf(const char *tagp);
791 extern long double __cdecl nanl(const char *tagp);
792
793 #ifndef __STRICT_ANSI__
794 #define _nan() nan("")
795 #define _nanf() nanf("")
796 #define _nanl() nanl("")
797 #endif
798
799 /* 7.12.11.3 */
800 extern double __cdecl nextafter (double, double); /* in libmoldname.a */
801 extern float __cdecl nextafterf (float, float);
802 extern long double __cdecl nextafterl (long double, long double);
803
804 /* 7.12.11.4 The nexttoward functions */
805 extern double __cdecl nexttoward (double,  long double);
806 extern float __cdecl nexttowardf (float,  long double);
807 extern long double __cdecl nexttowardl (long double, long double);
808
809 /* 7.12.12.1 */
810 /*  x > y ? (x - y) : 0.0  */
811 extern double __cdecl fdim (double x, double y);
812 extern float __cdecl fdimf (float x, float y);
813 extern long double __cdecl fdiml (long double x, long double y);
814
815 /* fmax and fmin.
816    NaN arguments are treated as missing data: if one argument is a NaN
817    and the other numeric, then these functions choose the numeric
818    value. */
819
820 /* 7.12.12.2 */
821 extern double __cdecl fmax  (double, double);
822 extern float __cdecl fmaxf (float, float);
823 extern long double __cdecl fmaxl (long double, long double);
824
825 /* 7.12.12.3 */
826 extern double __cdecl fmin (double, double);
827 extern float __cdecl fminf (float, float);
828 extern long double __cdecl fminl (long double, long double);
829
830 /* 7.12.13.1 */
831 /* return x * y + z as a ternary op */ 
832 extern double __cdecl fma (double, double, double);
833 extern float __cdecl fmaf (float, float, float);
834 extern long double __cdecl fmal (long double, long double, long double);
835
836
837 /* 7.12.14 */
838 /* 
839  *  With these functions, comparisons involving quiet NaNs set the FP
840  *  condition code to "unordered".  The IEEE floating-point spec
841  *  dictates that the result of floating-point comparisons should be
842  *  false whenever a NaN is involved, with the exception of the != op, 
843  *  which always returns true: yes, (NaN != NaN) is true).
844  */
845
846 #define isgreater(x, y) __builtin_isgreater(x, y)
847 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
848 #define isless(x, y) __builtin_isless(x, y)
849 #define islessequal(x, y) __builtin_islessequal(x, y)
850 #define islessgreater(x, y) __builtin_islessgreater(x, y)
851 #define isunordered(x, y) __builtin_isunordered(x, y)
852
853 #endif /* __STDC_VERSION__ >= 199901L */
854 #endif /* __NO_ISOCEXT */
855
856 #ifdef __cplusplus
857 }
858 #endif
859 #endif  /* Not RC_INVOKED */
860
861
862 #endif  /* Not _MATH_H_ */