Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * This file has no copyright assigned and is placed in the Public Domain.
  3.  * This file is part of the w64 mingw-runtime package.
  4.  * No warranty is given; refer to the file DISCLAIMER within this package.
  5.  */
  6. #ifndef _MATH_H_
  7. #define _MATH_H_
  8.  
  9. #if __GNUC__ >= 3
  10. #pragma GCC system_header
  11. #endif
  12.  
  13. #include <_mingw.h>
  14.  
  15. struct exception;
  16.  
  17. #pragma pack(push,_CRT_PACKING)
  18.  
  19. #define _DOMAIN 1
  20. #define _SING 2
  21. #define _OVERFLOW 3
  22. #define _UNDERFLOW 4
  23. #define _TLOSS 5
  24. #define _PLOSS 6
  25.  
  26. #ifndef __STRICT_ANSI__
  27. #ifndef NO_OLDNAMES
  28. #define DOMAIN _DOMAIN
  29. #define SING _SING
  30. #define OVERFLOW _OVERFLOW
  31. #define UNDERFLOW _UNDERFLOW
  32. #define TLOSS _TLOSS
  33. #define PLOSS _PLOSS
  34. #endif
  35. #endif
  36.  
  37. #ifndef __STRICT_ANSI__
  38. #define M_E 2.71828182845904523536
  39. #define M_LOG2E 1.44269504088896340736
  40. #define M_LOG10E 0.434294481903251827651
  41. #define M_LN2 0.693147180559945309417
  42. #define M_LN10 2.30258509299404568402
  43. #define M_PI 3.14159265358979323846
  44. #define M_PI_2 1.57079632679489661923
  45. #define M_PI_4 0.785398163397448309616
  46. #define M_1_PI 0.318309886183790671538
  47. #define M_2_PI 0.636619772367581343076
  48. #define M_2_SQRTPI 1.12837916709551257390
  49. #define M_SQRT2 1.41421356237309504880
  50. #define M_SQRT1_2 0.707106781186547524401
  51. #endif
  52.  
  53. #ifndef __STRICT_ANSI__
  54. /* See also float.h  */
  55. #ifndef __MINGW_FPCLASS_DEFINED
  56. #define __MINGW_FPCLASS_DEFINED 1
  57. #define _FPCLASS_SNAN   0x0001  /* Signaling "Not a Number" */
  58. #define _FPCLASS_QNAN   0x0002  /* Quiet "Not a Number" */
  59. #define _FPCLASS_NINF   0x0004  /* Negative Infinity */
  60. #define _FPCLASS_NN     0x0008  /* Negative Normal */
  61. #define _FPCLASS_ND     0x0010  /* Negative Denormal */
  62. #define _FPCLASS_NZ     0x0020  /* Negative Zero */
  63. #define _FPCLASS_PZ     0x0040  /* Positive Zero */
  64. #define _FPCLASS_PD     0x0080  /* Positive Denormal */
  65. #define _FPCLASS_PN     0x0100  /* Positive Normal */
  66. #define _FPCLASS_PINF   0x0200  /* Positive Infinity */
  67. #endif
  68. #endif
  69.  
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73.  
  74. #ifndef _EXCEPTION_DEFINED
  75. #define _EXCEPTION_DEFINED
  76.   struct _exception {
  77.     int type;
  78.     char *name;
  79.     double arg1;
  80.     double arg2;
  81.     double retval;
  82.   };
  83. #endif
  84.  
  85. #ifndef _COMPLEX_DEFINED
  86. #define _COMPLEX_DEFINED
  87.   struct _complex {
  88.     double x,y;
  89.   };
  90. #endif
  91.  
  92. #define EDOM 33
  93. #define ERANGE 34
  94.  
  95. #ifndef _HUGE
  96. #ifdef _MSVCRT_
  97.   extern double *_HUGE;
  98. #else
  99.   extern double *_imp___HUGE;
  100. #define _HUGE   (*_imp___HUGE)
  101. #endif
  102. #endif
  103.  
  104. #define HUGE_VAL _HUGE
  105.  
  106. #ifndef _CRT_ABS_DEFINED
  107. #define _CRT_ABS_DEFINED
  108.   int __cdecl abs(int _X);
  109.   long __cdecl labs(long _X);
  110. #endif
  111.   double __cdecl acos(double _X);
  112.   double __cdecl asin(double _X);
  113.   double __cdecl atan(double _X);
  114.   double __cdecl atan2(double _Y,double _X);
  115. #ifndef _SIGN_DEFINED
  116. #define _SIGN_DEFINED
  117.   _CRTIMP double __cdecl _copysign (double _Number,double _Sign);
  118.   _CRTIMP double __cdecl _chgsign (double _X);
  119. #endif
  120.   double __cdecl cos(double _X);
  121.   double __cdecl cosh(double _X);
  122.   double __cdecl exp(double _X);
  123.   double __cdecl expm1(double _X);
  124.   double __cdecl fabs(double _X);
  125.   double __cdecl fmod(double _X,double _Y);
  126.   double __cdecl log(double _X);
  127.   double __cdecl log10(double _X);
  128.   double __cdecl pow(double _X,double _Y);
  129.   double __cdecl sin(double _X);
  130.   double __cdecl sinh(double _X);
  131.   double __cdecl tan(double _X);
  132.   double __cdecl tanh(double _X);
  133.   double __cdecl sqrt(double _X);
  134. #ifndef _CRT_ATOF_DEFINED
  135. #define _CRT_ATOF_DEFINED
  136.   double __cdecl atof(const char *_String);
  137.   double __cdecl _atof_l(const char *_String,_locale_t _Locale);
  138. #endif
  139.  
  140.   _CRTIMP double __cdecl _cabs(struct _complex _ComplexA);
  141.   double __cdecl ceil(double _X);
  142.   double __cdecl floor(double _X);
  143.   double __cdecl frexp(double _X,int *_Y);
  144.   double __cdecl _hypot(double _X,double _Y);
  145.   _CRTIMP double __cdecl _j0(double _X);
  146.   _CRTIMP double __cdecl _j1(double _X);
  147.   _CRTIMP double __cdecl _jn(int _X,double _Y);
  148.   double __cdecl ldexp(double _X,int _Y);
  149. #ifndef _CRT_MATHERR_DEFINED
  150. #define _CRT_MATHERR_DEFINED
  151.   int __cdecl _matherr(struct _exception *_Except);
  152. #endif
  153.   double __cdecl modf(double _X,double *_Y);
  154.   _CRTIMP double __cdecl _y0(double _X);
  155.   _CRTIMP double __cdecl _y1(double _X);
  156.   _CRTIMP double __cdecl _yn(int _X,double _Y);
  157.  
  158. #if(defined(_X86_) && !defined(__x86_64))
  159.   _CRTIMP int __cdecl _set_SSE2_enable(int _Flag);
  160.   /* from libmingwex */
  161.   float __cdecl _hypotf(float _X,float _Y);
  162. #endif
  163.  
  164.   float frexpf(float _X,int *_Y);
  165.   float __cdecl ldexpf(float _X,int _Y);
  166.   long double __cdecl ldexpl(long double _X,int _Y);
  167.   float __cdecl acosf(float _X);
  168.   float __cdecl asinf(float _X);
  169.    float __cdecl atanf(float _X);
  170.    float __cdecl atan2f(float _X,float _Y);
  171.    float __cdecl cosf(float _X);
  172.    float __cdecl sinf(float _X);
  173.    float __cdecl tanf(float _X);
  174.    float __cdecl coshf(float _X);
  175.    float __cdecl sinhf(float _X);
  176.    float __cdecl tanhf(float _X);
  177.    float __cdecl expf(float _X);
  178.    float __cdecl expm1f(float _X);
  179.    float __cdecl logf(float _X);
  180.    float __cdecl log10f(float _X);
  181.    float __cdecl modff(float _X,float *_Y);
  182.    float __cdecl powf(float _X,float _Y);
  183.    float __cdecl sqrtf(float _X);
  184.    float __cdecl ceilf(float _X);
  185.    float __cdecl floorf(float _X);
  186.   float __cdecl fmodf(float _X,float _Y);
  187.    float __cdecl _hypotf(float _X,float _Y);
  188.   float __cdecl fabsf(float _X);
  189. #if !defined(__ia64__)
  190.    /* from libmingwex */
  191.    float __cdecl _copysignf (float _Number,float _Sign);
  192.    float __cdecl _chgsignf (float _X);
  193.    float __cdecl _logbf(float _X);
  194.    float __cdecl _nextafterf(float _X,float _Y);
  195.    int __cdecl _finitef(float _X);
  196.    int __cdecl _isnanf(float _X);
  197.    int __cdecl _fpclassf(float _X);
  198. #endif
  199.  
  200. #ifndef __cplusplus
  201.   __CRT_INLINE long double __cdecl fabsl (long double x)
  202.   {
  203.     long double res;
  204.     __asm__ ("fabs;" : "=t" (res) : "0" (x));
  205.     return res;
  206.   }
  207. #define _hypotl(x,y) ((long double)_hypot((double)(x),(double)(y)))
  208. #define _matherrl _matherr
  209.   __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign((double)(_Number)); }
  210.   __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign((double)(_Number),(double)(_Sign)); }
  211.   __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
  212.  
  213. #if !defined (__ia64__)
  214.   __CRT_INLINE float __cdecl fabsf (float x)
  215.   {
  216.     float res;
  217.     __asm__ ("fabs;" : "=t" (res) : "0" (x));
  218.     return res;
  219.   }
  220.  
  221.   __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
  222. #endif
  223. #else
  224.   // cplusplus
  225.   __CRT_INLINE long double __cdecl fabsl (long double x)
  226.   {
  227.     long double res;
  228.     __asm__ ("fabs;" : "=t" (res) : "0" (x));
  229.     return res;
  230.   }
  231.   __CRT_INLINE long double modfl(long double _X,long double *_Y) {
  232.     double _Di,_Df = modf((double)_X,&_Di);
  233.     *_Y = (long double)_Di;
  234.     return (_Df);
  235.   }
  236.   __CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign(static_cast<double>(_Number)); }
  237.   __CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign(static_cast<double>(_Number),static_cast<double>(_Sign)); }
  238.   __CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
  239. #ifndef __ia64__
  240.   __CRT_INLINE float __cdecl fabsf (float x)
  241.   {
  242.     float res;
  243.     __asm__ ("fabs;" : "=t" (res) : "0" (x));
  244.     return res;
  245.   }
  246.   __CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
  247. #ifndef __x86_64
  248.   __CRT_INLINE float acosf(float _X) { return ((float)acos((double)_X)); }
  249.   __CRT_INLINE float asinf(float _X) { return ((float)asin((double)_X)); }
  250.   __CRT_INLINE float atanf(float _X) { return ((float)atan((double)_X)); }
  251.   __CRT_INLINE float atan2f(float _X,float _Y) { return ((float)atan2((double)_X,(double)_Y)); }
  252.   __CRT_INLINE float ceilf(float _X) { return ((float)ceil((double)_X)); }
  253.   __CRT_INLINE float cosf(float _X) { return ((float)cos((double)_X)); }
  254.   __CRT_INLINE float coshf(float _X) { return ((float)cosh((double)_X)); }
  255.   __CRT_INLINE float expf(float _X) { return ((float)exp((double)_X)); }
  256.   __CRT_INLINE float floorf(float _X) { return ((float)floor((double)_X)); }
  257.   __CRT_INLINE float fmodf(float _X,float _Y) { return ((float)fmod((double)_X,(double)_Y)); }
  258.   __CRT_INLINE float logf(float _X) { return ((float)log((double)_X)); }
  259.   __CRT_INLINE float log10f(float _X) { return ((float)log10((double)_X)); }
  260.   __CRT_INLINE float modff(float _X,float *_Y) {
  261.     double _Di,_Df = modf((double)_X,&_Di);
  262.     *_Y = (float)_Di;
  263.     return ((float)_Df);
  264.   }
  265.   __CRT_INLINE float powf(float _X,float _Y) { return ((float)pow((double)_X,(double)_Y)); }
  266.   __CRT_INLINE float sinf(float _X) { return ((float)sin((double)_X)); }
  267.   __CRT_INLINE float sinhf(float _X) { return ((float)sinh((double)_X)); }
  268.   __CRT_INLINE float sqrtf(float _X) { return ((float)sqrt((double)_X)); }
  269.   __CRT_INLINE float tanf(float _X) { return ((float)tan((double)_X)); }
  270.   __CRT_INLINE float tanhf(float _X) { return ((float)tanh((double)_X)); }
  271. #endif
  272. #endif
  273. #endif
  274.  
  275. #ifndef NO_OLDNAMES
  276. #define matherr _matherr
  277.  
  278. #define HUGE    _HUGE
  279.   /*    double __cdecl cabs(struct _complex _X); */
  280.   double __cdecl hypot(double _X,double _Y);
  281.   _CRTIMP double __cdecl j0(double _X);
  282.   _CRTIMP double __cdecl j1(double _X);
  283.   _CRTIMP double __cdecl jn(int _X,double _Y);
  284.   _CRTIMP double __cdecl y0(double _X);
  285.   _CRTIMP double __cdecl y1(double _X);
  286.   _CRTIMP double __cdecl yn(int _X,double _Y);
  287. #endif
  288.  
  289. #ifndef __NO_ISOCEXT
  290. #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
  291.   || !defined __STRICT_ANSI__ || defined __GLIBCPP__
  292.  
  293. #define NAN (0.0F/0.0F)
  294. #define HUGE_VALF (1.0F/0.0F)
  295. #define HUGE_VALL (1.0L/0.0L)
  296. #define INFINITY (1.0F/0.0F)
  297.  
  298.  
  299. #define FP_NAN          0x0100
  300. #define FP_NORMAL       0x0400
  301. #define FP_INFINITE     (FP_NAN | FP_NORMAL)
  302. #define FP_ZERO         0x4000
  303. #define FP_SUBNORMAL    (FP_NORMAL | FP_ZERO)
  304.   /* 0x0200 is signbit mask */
  305.  
  306.  
  307.   /*
  308.   We can't __CRT_INLINE float or double, because we want to ensure truncation
  309.   to semantic type before classification.
  310.   (A normal long double value might become subnormal when
  311.   converted to double, and zero when converted to float.)
  312.   */
  313.  
  314.   extern int __cdecl __fpclassifyf (float);
  315.   extern int __cdecl __fpclassify (double);
  316.   extern int __cdecl __fpclassifyl (long double);
  317.  
  318. /* Implemented at tcc/tcc_libm.h */
  319. #define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x)   \
  320.   : sizeof (x) == sizeof (double) ? __fpclassify (x) \
  321.   : __fpclassifyl (x))
  322.  
  323.   /* 7.12.3.2 */
  324. #define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)
  325.  
  326.   /* 7.12.3.3 */
  327. #define isinf(x) (fpclassify(x) == FP_INFINITE)
  328.  
  329.   /* 7.12.3.4 */
  330.   /* We don't need to worry about trucation here:
  331.   A NaN stays a NaN. */
  332. #define isnan(x) (fpclassify(x) == FP_NAN)
  333.  
  334.   /* 7.12.3.5 */
  335. #define isnormal(x) (fpclassify(x) == FP_NORMAL)
  336.  
  337.   /* 7.12.3.6 The signbit macro */
  338.  
  339.   extern int __cdecl __signbitf (float);
  340.   extern int __cdecl __signbit (double);
  341.   extern int __cdecl __signbitl (long double);
  342.  
  343. /* Implemented at tcc/tcc_libm.h */
  344. #define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x)       \
  345.   : sizeof (x) == sizeof (double) ? __signbit (x)       \
  346.   : __signbitl (x))
  347.  
  348.   extern double __cdecl exp2(double);
  349.   extern float __cdecl exp2f(float);
  350.   extern long double __cdecl exp2l(long double);
  351.  
  352. #define FP_ILOGB0 ((int)0x80000000)
  353. #define FP_ILOGBNAN ((int)0x80000000)
  354.   extern int __cdecl ilogb (double);
  355.   extern int __cdecl ilogbf (float);
  356.   extern int __cdecl ilogbl (long double);
  357.  
  358.   extern double __cdecl log1p(double);
  359.   extern float __cdecl log1pf(float);
  360.   extern long double __cdecl log1pl(long double);
  361.  
  362.   extern double __cdecl log2 (double);
  363.   extern float __cdecl log2f (float);
  364.   extern long double __cdecl log2l (long double);
  365.  
  366.   extern double __cdecl logb (double);
  367.   extern float __cdecl logbf (float);
  368.   extern long double __cdecl logbl (long double);
  369.  
  370.   __CRT_INLINE double __cdecl logb (double x)
  371.   {
  372.     double res;
  373.     __asm__ ("fxtract\n\t"
  374.       "fstp     %%st" : "=t" (res) : "0" (x));
  375.     return res;
  376.   }
  377.  
  378.   __CRT_INLINE float __cdecl logbf (float x)
  379.   {
  380.     float res;
  381.     __asm__ ("fxtract\n\t"
  382.       "fstp     %%st" : "=t" (res) : "0" (x));
  383.     return res;
  384.   }
  385.  
  386.   __CRT_INLINE long double __cdecl logbl (long double x)
  387.   {
  388.     long double res;
  389.     __asm__ ("fxtract\n\t"
  390.       "fstp     %%st" : "=t" (res) : "0" (x));
  391.     return res;
  392.   }
  393.  
  394.   extern long double __cdecl modfl (long double, long double*);
  395.  
  396.   /* 7.12.6.13 */
  397.   extern double __cdecl scalbn (double, int);
  398.   extern float __cdecl scalbnf (float, int);
  399.   extern long double __cdecl scalbnl (long double, int);
  400.  
  401.   extern double __cdecl scalbln (double, long);
  402.   extern float __cdecl scalblnf (float, long);
  403.   extern long double __cdecl scalblnl (long double, long);
  404.  
  405.   /* 7.12.7.1 */
  406.   /* Implementations adapted from Cephes versions */
  407.   extern double __cdecl cbrt (double);
  408.   extern float __cdecl cbrtf (float);
  409.   extern long double __cdecl cbrtl (long double);
  410.  
  411.   __CRT_INLINE float __cdecl hypotf (float x, float y)
  412.   { return (float) hypot (x, y);}
  413.   extern long double __cdecl hypotl (long double, long double);
  414.  
  415.   extern long double __cdecl powl (long double, long double);
  416.   extern long double __cdecl expl(long double);
  417.   extern long double __cdecl expm1l(long double);
  418.   extern long double __cdecl coshl(long double);
  419.   extern long double __cdecl fabsl (long double);
  420.   extern long double __cdecl acosl(long double);
  421.   extern long double __cdecl asinl(long double);
  422.   extern long double __cdecl atanl(long double);
  423.   extern long double __cdecl atan2l(long double,long double);
  424.   extern long double __cdecl sinhl(long double);
  425.   extern long double __cdecl tanhl(long double);
  426.  
  427.   /* 7.12.8.1 The erf functions  */
  428.   extern double __cdecl erf (double);
  429.   extern float __cdecl erff (float);
  430.   /* TODO
  431.   extern long double __cdecl erfl (long double);
  432.   */
  433.  
  434.   /* 7.12.8.2 The erfc functions  */
  435.   extern double __cdecl erfc (double);
  436.   extern float __cdecl erfcf (float);
  437.   /* TODO
  438.   extern long double __cdecl erfcl (long double);
  439.   */
  440.  
  441.   /* 7.12.8.3 The lgamma functions */
  442.   extern double __cdecl lgamma (double);
  443.   extern float __cdecl lgammaf (float);
  444.   extern long double __cdecl lgammal (long double);
  445.  
  446.   /* 7.12.8.4 The tgamma functions */
  447.   extern double __cdecl tgamma (double);
  448.   extern float __cdecl tgammaf (float);
  449.   extern long double __cdecl tgammal (long double);
  450.  
  451.   extern long double __cdecl ceill (long double);
  452.   extern long double __cdecl floorl (long double);
  453.   extern long double __cdecl frexpl(long double,int *);
  454.   extern long double __cdecl log10l(long double);
  455.   extern long double __cdecl logl(long double);
  456.   extern long double __cdecl cosl(long double);
  457.   extern long double __cdecl sinl(long double);
  458.   extern long double __cdecl tanl(long double);
  459.   extern long double sqrtl(long double);
  460.  
  461.   /* 7.12.9.3 */
  462.   extern double __cdecl nearbyint ( double);
  463.   extern float __cdecl nearbyintf (float);
  464.   extern long double __cdecl nearbyintl (long double);
  465.  
  466.   /* 7.12.9.4 */
  467.   /* round, using fpu control word settings */
  468.   __CRT_INLINE double __cdecl rint (double x)
  469.   {
  470.     double retval;
  471.     __asm__ (
  472.       "fldl    %1\n"
  473.       "frndint   \n"
  474.       "fstl    %0\n" : "=m" (retval) : "m" (x));
  475.     return retval;
  476.   }
  477.  
  478.   __CRT_INLINE float __cdecl rintf (float x)
  479.   {
  480.     float retval;
  481.     __asm__ (
  482.       "flds    %1\n"
  483.       "frndint   \n"
  484.       "fsts    %0\n" : "=m" (retval) : "m" (x));
  485.     return retval;
  486.   }
  487.  
  488.   __CRT_INLINE long double __cdecl rintl (long double x)
  489.   {
  490.     long double retval;
  491.     __asm__ (
  492.       "fldt    %1\n"
  493.       "frndint   \n"
  494.       "fstt    %0\n" : "=m" (retval) : "m" (x));
  495.     return retval;
  496.   }
  497.  
  498.   /* 7.12.9.5 */
  499.   __CRT_INLINE long __cdecl lrint (double x)
  500.   {
  501.     long retval;  
  502.     __asm__ __volatile__                         \
  503.       ("fldl   %1\n"                             \
  504.        "fistpl %0"  : "=m" (retval) : "m" (x));  \
  505.       return retval;
  506.   }
  507.  
  508.   __CRT_INLINE long __cdecl lrintf (float x)
  509.   {
  510.     long retval;
  511.     __asm__ __volatile__                         \
  512.       ("flds   %1\n"                             \
  513.        "fistpl %0"  : "=m" (retval) : "m" (x));  \
  514.       return retval;
  515.   }
  516.  
  517.   __CRT_INLINE long __cdecl lrintl (long double x)
  518.   {
  519.     long retval;
  520.     __asm__ __volatile__                         \
  521.       ("fldt   %1\n"                             \
  522.        "fistpl %0"  : "=m" (retval) : "m" (x));  \
  523.       return retval;
  524.   }
  525.  
  526.   __CRT_INLINE long long __cdecl llrint (double x)
  527.   {
  528.     long long retval;
  529.     __asm__ __volatile__                         \
  530.       ("fldl    %1\n"                            \
  531.        "fistpll %0"  : "=m" (retval) : "m" (x)); \
  532.       return retval;
  533.   }
  534.  
  535.   __CRT_INLINE long long __cdecl llrintf (float x)
  536.   {
  537.     long long retval;
  538.     __asm__ __volatile__                         \
  539.       ("flds   %1\n"                             \
  540.        "fistpll %0"  : "=m" (retval) : "m" (x)); \
  541.       return retval;
  542.   }
  543.  
  544.   __CRT_INLINE long long __cdecl llrintl (long double x)
  545.   {
  546.     long long retval;
  547.     __asm__ __volatile__                         \
  548.       ("fldt    %1\n"                            \
  549.        "fistpll %0"  : "=m" (retval) : "m" (x)); \
  550.       return retval;
  551.   }
  552.  
  553.   #define FE_TONEAREST  0x0000
  554.   #define FE_DOWNWARD   0x0400
  555.   #define FE_UPWARD     0x0800
  556.   #define FE_TOWARDZERO 0x0c00
  557.  
  558.   __CRT_INLINE double trunc (double _x)
  559.   {
  560.     double retval;
  561.     unsigned short saved_cw;
  562.     unsigned short tmp_cw;
  563.     __asm__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
  564.     tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
  565.             | FE_TOWARDZERO;
  566.     __asm__ ("fldcw %0;" : : "m" (tmp_cw));
  567.     __asm__ ("fldl  %1;"
  568.              "frndint;"
  569.              "fstl  %0;" : "=m" (retval)  : "m" (_x)); /* round towards zero */
  570.     __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
  571.     return retval;
  572.   }
  573.  
  574.   /* 7.12.9.6 */
  575.   /* round away from zero, regardless of fpu control word settings */
  576.   extern double __cdecl round (double);
  577.   extern float __cdecl roundf (float);
  578.   extern long double __cdecl roundl (long double);
  579.  
  580.   /* 7.12.9.7  */
  581.   extern long __cdecl lround (double);
  582.   extern long __cdecl lroundf (float);
  583.   extern long __cdecl lroundl (long double);
  584.  
  585.   extern long long __cdecl llround (double);
  586.   extern long long __cdecl llroundf (float);
  587.   extern long long __cdecl llroundl (long double);
  588.  
  589.   /* 7.12.9.8 */
  590.   /* round towards zero, regardless of fpu control word settings */
  591.   extern double __cdecl trunc (double);
  592.   extern float __cdecl truncf (float);
  593.   extern long double __cdecl truncl (long double);
  594.  
  595.   extern long double __cdecl fmodl (long double, long double);
  596.  
  597.   /* 7.12.10.2 */
  598.   extern double __cdecl remainder (double, double);
  599.   extern float __cdecl remainderf (float, float);
  600.   extern long double __cdecl remainderl (long double, long double);
  601.  
  602.   /* 7.12.10.3 */
  603.   extern double __cdecl remquo(double, double, int *);
  604.   extern float __cdecl remquof(float, float, int *);
  605.   extern long double __cdecl remquol(long double, long double, int *);
  606.  
  607.   /* 7.12.11.1 */
  608.   extern double __cdecl copysign (double, double); /* in libmoldname.a */
  609.   extern float __cdecl copysignf (float, float);
  610.   extern long double __cdecl copysignl (long double, long double);
  611.  
  612.   /* 7.12.11.2 Return a NaN */
  613.   extern double __cdecl nan(const char *tagp);
  614.   extern float __cdecl nanf(const char *tagp);
  615.   extern long double __cdecl nanl(const char *tagp);
  616.  
  617. #ifndef __STRICT_ANSI__
  618. #define _nan() nan("")
  619. #define _nanf() nanf("")
  620. #define _nanl() nanl("")
  621. #endif
  622.  
  623.   /* 7.12.11.3 */
  624.   extern double __cdecl nextafter (double, double); /* in libmoldname.a */
  625.   extern float __cdecl nextafterf (float, float);
  626.   extern long double __cdecl nextafterl (long double, long double);
  627.  
  628.   /* 7.12.11.4 The nexttoward functions: TODO */
  629.  
  630.   /* 7.12.12.1 */
  631.   /*  x > y ? (x - y) : 0.0  */
  632.   extern double __cdecl fdim (double x, double y);
  633.   extern float __cdecl fdimf (float x, float y);
  634.   extern long double __cdecl fdiml (long double x, long double y);
  635.  
  636.   /* fmax and fmin.
  637.   NaN arguments are treated as missing data: if one argument is a NaN
  638.   and the other numeric, then these functions choose the numeric
  639.   value. */
  640.  
  641.   /* 7.12.12.2 */
  642.   extern double __cdecl fmax  (double, double);
  643.   extern float __cdecl fmaxf (float, float);
  644.   extern long double __cdecl fmaxl (long double, long double);
  645.  
  646.   /* 7.12.12.3 */
  647.   extern double __cdecl fmin (double, double);
  648.   extern float __cdecl fminf (float, float);
  649.   extern long double __cdecl fminl (long double, long double);
  650.  
  651.   /* 7.12.13.1 */
  652.   /* return x * y + z as a ternary op */
  653.   extern double __cdecl fma (double, double, double);
  654.   extern float __cdecl fmaf (float, float, float);
  655.   extern long double __cdecl fmal (long double, long double, long double);
  656.  
  657.  
  658. #if 0 // gr: duplicate, see below
  659.   /* 7.12.14 */
  660.   /*
  661.   *  With these functions, comparisons involving quiet NaNs set the FP
  662.   *  condition code to "unordered".  The IEEE floating-point spec
  663.   *  dictates that the result of floating-point comparisons should be
  664.   *  false whenever a NaN is involved, with the exception of the != op,
  665.   *  which always returns true: yes, (NaN != NaN) is true).
  666.   */
  667.  
  668. #if __GNUC__ >= 3
  669.  
  670. #define isgreater(x, y) __builtin_isgreater(x, y)
  671. #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
  672. #define isless(x, y) __builtin_isless(x, y)
  673. #define islessequal(x, y) __builtin_islessequal(x, y)
  674. #define islessgreater(x, y) __builtin_islessgreater(x, y)
  675. #define isunordered(x, y) __builtin_isunordered(x, y)
  676.  
  677. #else
  678.   /*  helper  */
  679.   __CRT_INLINE int  __cdecl
  680.     __fp_unordered_compare (long double x, long double y){
  681.       unsigned short retval;
  682.       __asm__ ("fucom %%st(1);"
  683.         "fnstsw;": "=a" (retval) : "t" (x), "u" (y));
  684.       return retval;
  685.   }
  686.  
  687. #define isgreater(x, y) ((__fp_unordered_compare(x, y) \
  688.   & 0x4500) == 0)
  689. #define isless(x, y) ((__fp_unordered_compare (y, x) \
  690.   & 0x4500) == 0)
  691. #define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \
  692.   & FP_INFINITE) == 0)
  693. #define islessequal(x, y) ((__fp_unordered_compare(y, x) \
  694.   & FP_INFINITE) == 0)
  695. #define islessgreater(x, y) ((__fp_unordered_compare(x, y) \
  696.   & FP_SUBNORMAL) == 0)
  697. #define isunordered(x, y) ((__fp_unordered_compare(x, y) \
  698.   & 0x4500) == 0x4500)
  699.  
  700. #endif
  701. #endif //0
  702.  
  703.  
  704. #endif /* __STDC_VERSION__ >= 199901L */
  705. #endif /* __NO_ISOCEXT */
  706.  
  707. #ifdef __cplusplus
  708. }
  709. extern "C++" {
  710.   template<class _Ty> inline _Ty _Pow_int(_Ty _X,int _Y) {
  711.     unsigned int _N;
  712.     if(_Y >= 0) _N = (unsigned int)_Y;
  713.     else _N = (unsigned int)(-_Y);
  714.     for(_Ty _Z = _Ty(1);;_X *= _X) {
  715.       if((_N & 1)!=0) _Z *= _X;
  716.       if((_N >>= 1)==0) return (_Y < 0 ? _Ty(1) / _Z : _Z);
  717.     }
  718.   }
  719. }
  720. #endif
  721.  
  722. #pragma pack(pop)
  723.  
  724. /* 7.12.14 */
  725. /*
  726.  *  With these functions, comparisons involving quiet NaNs set the FP
  727.  *  condition code to "unordered".  The IEEE floating-point spec
  728.  *  dictates that the result of floating-point comparisons should be
  729.  *  false whenever a NaN is involved, with the exception of the != op,
  730.  *  which always returns true: yes, (NaN != NaN) is true).
  731.  */
  732.  
  733. /* Mini libm (inline __fpclassify*, __signbit* and variants) */
  734. #include "tcc/tcc_libm.h"
  735.  
  736. #endif /* End _MATH_H_ */
  737.  
  738.