OSDN Git Service

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