OSDN Git Service

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