OSDN Git Service

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