home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / include / math.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  19.0 KB  |  772 lines

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