home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / h / math < prev    next >
Encoding:
Text File  |  2006-09-17  |  15.1 KB  |  471 lines

  1. /* Declarations for math functions.
  2.    Copyright (C) 1991-1993,1995-1999,2001,2002 Free Software Foundation, Inc.
  3.    This file is part of the GNU C Library.
  4.  
  5.    The GNU C Library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Lesser General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2.1 of the License, or (at your option) any later version.
  9.  
  10.    The GNU C Library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Lesser General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Lesser General Public
  16.    License along with the GNU C Library; if not, write to the Free
  17.    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18.    02111-1307 USA.  */
  19.  
  20. /*
  21.  *    ISO C99 Standard: 7.12 Mathematics    <math.h>
  22.  */
  23.  
  24. #ifndef    _MATH_H
  25. #define    _MATH_H    1
  26.  
  27. #include <features.h>
  28.  
  29. __BEGIN_DECLS
  30.  
  31. /* Get machine-dependent HUGE_VAL value (returned on overflow).
  32.    On all IEEE754 machines, this is +Infinity.  */
  33. #include <bits/huge_val.h>
  34.  
  35. #ifdef     __USE_ISOC99
  36. # include <bits/huge_valf.h>
  37. # include <bits/huge_vall.h>
  38.  
  39. /* Get machine-dependent NAN value (returned for some domain errors).  */
  40. # include <bits/nan.h>
  41.  
  42. /* Get machine-dependent Infinity value.  */
  43. # include <bits/inf.h>
  44. #endif
  45. /* Get general and ISO C99 specific information.  */
  46. #include <bits/mathdef.h>
  47.  
  48.  
  49. /* The file <bits/mathcalls.h> contains the prototypes for all the
  50.    actual math functions.  These macros are used for those prototypes,
  51.    so we can easily declare each function as both `name' and `__name',
  52.    and can declare the float versions `namef' and `__namef'.  */
  53.  
  54. #define __MATHCALL(function,suffix, args)    \
  55.   __MATHDECL (_Mdouble_,function,suffix, args)
  56. #define __MATHDECL(type, function,suffix, args) \
  57.   __MATHDECL_1(type, function,suffix, args); \
  58.   __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
  59. #define __MATHCALLX(function,suffix, args, attrib)    \
  60.   __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
  61. #define __MATHDECLX(type, function,suffix, args, attrib) \
  62.   __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
  63.   __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
  64. #define __MATHDECL_1(type, function,suffix, args) \
  65.   extern type __MATH_PRECNAME(function,suffix) args __THROW
  66.  
  67. #define _Mdouble_         double
  68. #define __MATH_PRECNAME(name,r)    __CONCAT(name,r)
  69. # define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
  70. # define _Mdouble_END_NAMESPACE   __END_NAMESPACE_STD
  71. #include <bits/mathcalls.h>
  72. #undef    _Mdouble_
  73. #undef _Mdouble_BEGIN_NAMESPACE
  74. #undef _Mdouble_END_NAMESPACE
  75. #undef    __MATH_PRECNAME
  76.  
  77. #if defined __USE_MISC || defined __USE_ISOC99
  78.  
  79.  
  80. /* Include the file of declarations again, this time using `float'
  81.    instead of `double' and appending f to each function name.  */
  82.  
  83. # ifndef _Mfloat_
  84. #  define _Mfloat_        float
  85. # endif
  86. # define _Mdouble_         _Mfloat_
  87. # ifdef __STDC__
  88. #  define __MATH_PRECNAME(name,r) name##f##r
  89. # else
  90. #  define __MATH_PRECNAME(name,r) name/**/f/**/r
  91. # endif
  92. # define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
  93. # define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
  94. # include <bits/mathcalls.h>
  95. # undef    _Mdouble_
  96. # undef _Mdouble_BEGIN_NAMESPACE
  97. # undef _Mdouble_END_NAMESPACE
  98. # undef    __MATH_PRECNAME
  99.  
  100. # if (__STDC__ - 0 || __GNUC__ - 0) && !defined __NO_LONG_DOUBLE_MATH
  101. /* Include the file of declarations again, this time using `long double'
  102.    instead of `double' and appending l to each function name.  */
  103.  
  104. #  ifndef _Mlong_double_
  105. #   define _Mlong_double_    long double
  106. #  endif
  107. #  define _Mdouble_         _Mlong_double_
  108. #  ifdef __STDC__
  109. #   define __MATH_PRECNAME(name,r) name##l##r
  110. #  else
  111. #   define __MATH_PRECNAME(name,r) name/**/l/**/r
  112. #  endif
  113. #  define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
  114. #  define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
  115. #  include <bits/mathcalls.h>
  116. #  undef _Mdouble_
  117. # undef _Mdouble_BEGIN_NAMESPACE
  118. # undef _Mdouble_END_NAMESPACE
  119. #  undef __MATH_PRECNAME
  120.  
  121. # endif /* __STDC__ || __GNUC__ */
  122.  
  123. #endif    /* Use misc or ISO C99.  */
  124. #undef    __MATHDECL_1
  125. #undef    __MATHDECL
  126. #undef    __MATHCALL
  127.  
  128.  
  129. #if defined __USE_MISC || defined __USE_XOPEN
  130. /* This variable is used by `gamma' and `lgamma'.  */
  131. extern int signgam;
  132. #endif
  133.  
  134.  
  135. /* ISO C99 defines some generic macros which work on any data type.  */
  136. #if __USE_ISOC99
  137.  
  138. /* Get the architecture specific values describing the floating-point
  139.    evaluation.  The following symbols will get defined:
  140.  
  141.     float_t    floating-point type at least as wide as `float' used
  142.         to evaluate `float' expressions
  143.     double_t    floating-point type at least as wide as `double' used
  144.         to evaluate `double' expressions
  145.  
  146.     FLT_EVAL_METHOD
  147.         Defined to
  148.           0    if `float_t' is `float' and `double_t' is `double'
  149.           1    if `float_t' and `double_t' are `double'
  150.           2    if `float_t' and `double_t' are `long double'
  151.           else    `float_t' and `double_t' are unspecified
  152.  
  153.     INFINITY    representation of the infinity value of type `float'
  154.  
  155.     FP_FAST_FMA
  156.     FP_FAST_FMAF
  157.     FP_FAST_FMAL
  158.         If defined it indicates that the `fma' function
  159.         generally executes about as fast as a multiply and an add.
  160.         This macro is defined only iff the `fma' function is
  161.         implemented directly with a hardware multiply-add instructions.
  162.  
  163.     FP_ILOGB0    Expands to a value returned by `ilogb (0.0)'.
  164.     FP_ILOGBNAN    Expands to a value returned by `ilogb (NAN)'.
  165.  
  166.     DECIMAL_DIG    Number of decimal digits supported by conversion between
  167.         decimal and all internal floating-point formats.
  168.  
  169. */
  170.  
  171. /* All floating-point numbers can be put in one of these categories.  */
  172. enum
  173.   {
  174.     FP_NAN,
  175. # define FP_NAN FP_NAN
  176.     FP_INFINITE,
  177. # define FP_INFINITE FP_INFINITE
  178.     FP_ZERO,
  179. # define FP_ZERO FP_ZERO
  180.     FP_SUBNORMAL,
  181. # define FP_SUBNORMAL FP_SUBNORMAL
  182.     FP_NORMAL
  183. # define FP_NORMAL FP_NORMAL
  184.   };
  185.  
  186. /* Return number of classification appropriate for X.  */
  187. # ifdef __NO_LONG_DOUBLE_MATH
  188. #  define fpclassify(x) \
  189.      (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
  190. # else
  191. #  define fpclassify(x) \
  192.      (sizeof (x) == sizeof (float)                          \
  193.       ? __fpclassifyf (x)                              \
  194.       : sizeof (x) == sizeof (double)                          \
  195.       ? __fpclassify (x) : __fpclassifyl (x))
  196. # endif
  197.  
  198. /* Return nonzero value if sign of X is negative.  */
  199. # ifdef __NO_LONG_DOUBLE_MATH
  200. #  define signbit(x) \
  201.      (sizeof (x) == sizeof (float) ? __signbitf (x) : __signbit (x))
  202. # else
  203. #  define signbit(x) \
  204.      (sizeof (x) == sizeof (float)                          \
  205.       ? __signbitf (x)                                  \
  206.       : sizeof (x) == sizeof (double)                          \
  207.       ? __signbit (x) : __signbitl (x))
  208. # endif
  209.  
  210. /* Return nonzero value if X is not +-Inf or NaN.  */
  211. # ifdef __NO_LONG_DOUBLE_MATH
  212. #  define isfinite(x) \
  213.      (sizeof (x) == sizeof (float) ? __finitef (x) : __finite (x))
  214. # else
  215. #  define isfinite(x) \
  216.      (sizeof (x) == sizeof (float)                          \
  217.       ? __finitef (x)                                  \
  218.       : sizeof (x) == sizeof (double)                          \
  219.       ? __finite (x) : __finitel (x))
  220. # endif
  221.  
  222. /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN.  */
  223. # define isnormal(x) (fpclassify (x) == FP_NORMAL)
  224.  
  225. /* Return nonzero value if X is a NaN.  We could use `fpclassify' but
  226.    we already have this functions `__isnan' and it is faster.  */
  227. # if defined(__CC_NORCROFT) || defined(__LCC__)
  228. extern int isnanf (float x);
  229. extern int isnan (double x);
  230. #  define isnan(x) \
  231.        (sizeof (x) == sizeof (float) ? isnanf (x) : isnan (x))
  232. # else /* GNUC */
  233. #  ifdef __NO_LONG_DOUBLE_MATH
  234. #   define isnan(x) \
  235.        (sizeof (x) == sizeof (float) ? __isnanf (x) : __isnan (x))
  236. #  else
  237. #   define isnan(x) \
  238.        (sizeof (x) == sizeof (float)                                          \
  239.         ? __isnanf (x)                                                        \
  240.         : sizeof (x) == sizeof (double)                                       \
  241.         ? __isnan (x) : __isnanl (x))
  242. #  endif
  243. # endif /* !__CC_NORCROFT && !__LCC__ */
  244.  
  245. /* Return nonzero value is X is positive or negative infinity.  */
  246. # if defined(__CC_NORCROFT) || defined(__LCC__)
  247. extern int isinff (float x);
  248. extern int isinf (double x);
  249. #  define isinf(x) \
  250.        (sizeof (x) == sizeof (float) ? isinff (x) : isinf (x))
  251. # else /* GNUC */
  252. #  ifdef __NO_LONG_DOUBLE_MATH
  253. #   define isinf(x) \
  254.        (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
  255. #  else
  256. #   define isinf(x) \
  257.        (sizeof (x) == sizeof (float)                                          \
  258.         ? __isinff (x)                                                        \
  259.         : sizeof (x) == sizeof (double)                                       \
  260.         ? __isinf (x) : __isinfl (x))
  261. #  endif
  262. # endif /* !__CC_NORCROFT && !__LCC__ */
  263.  
  264. /* Bitmasks for the math_errhandling macro.  */
  265. # define MATH_ERRNO    1    /* errno set by math functions.  */
  266. # define MATH_ERREXCEPT    2    /* Exceptions raised by math functions.  */
  267.  
  268. #endif /* Use ISO C99.  */
  269.  
  270. #ifdef    __USE_MISC
  271. /* Support for various different standard error handling behaviors.  */
  272. typedef enum
  273. {
  274.   _IEEE_ = -1,    /* According to IEEE 754/IEEE 854.  */
  275.   _SVID_,    /* According to System V, release 4.  */
  276.   _XOPEN_,    /* Nowadays also Unix98.  */
  277.   _POSIX_,
  278.   _ISOC_    /* Actually this is ISO C99.  */
  279. } _LIB_VERSION_TYPE;
  280.  
  281. /* This variable can be changed at run-time to any of the values above to
  282.    affect floating point error handling behavior (it may also be necessary
  283.    to change the hardware FPU exception settings).  */
  284. extern _LIB_VERSION_TYPE _LIB_VERSION;
  285. #endif
  286.  
  287.  
  288. #ifdef __USE_SVID
  289. /* In SVID error handling, `matherr' is called with this description
  290.    of the exceptional condition.
  291.  
  292.    We have a problem when using C++ since `exception' is a reserved
  293.    name in C++.  */
  294. # ifdef __cplusplus
  295. struct __exception
  296. # else
  297. struct exception
  298. # endif
  299.   {
  300.     int type;
  301.     const char *name;
  302.     double arg1;
  303.     double arg2;
  304.     double retval;
  305.   };
  306.  
  307. # ifdef __cplusplus
  308. extern int matherr (struct __exception *__exc) throw ();
  309. # else
  310. extern int matherr (struct exception *__exc);
  311. # endif
  312.  
  313. # define X_TLOSS    1.41484755040568800000e+16
  314.  
  315. /* Types of exceptions in the `type' field.  */
  316. # define DOMAIN        1
  317. # define SING        2
  318. # define OVERFLOW    3
  319. # define UNDERFLOW    4
  320. # define TLOSS        5
  321. # define PLOSS        6
  322.  
  323. /* SVID mode specifies returning this large value instead of infinity.  */
  324. # define HUGE        3.40282347e+38F
  325.  
  326. #else    /* !SVID */
  327.  
  328. # ifdef __USE_XOPEN
  329. /* X/Open wants another strange constant.  */
  330. #  define MAXFLOAT    3.40282347e+38F
  331. # endif
  332.  
  333. #endif    /* SVID */
  334.  
  335.  
  336. /* Some useful constants.  */
  337. #if defined __USE_BSD || defined __USE_XOPEN
  338. # define M_E        2.7182818284590452354    /* e */
  339. # define M_LOG2E    1.4426950408889634074    /* log_2 e */
  340. # define M_LOG10E    0.43429448190325182765    /* log_10 e */
  341. # define M_LN2        0.69314718055994530942    /* log_e 2 */
  342. # define M_LN10        2.30258509299404568402    /* log_e 10 */
  343. # define M_PI        3.14159265358979323846    /* pi */
  344. # define M_PI_2        1.57079632679489661923    /* pi/2 */
  345. # define M_PI_4        0.78539816339744830962    /* pi/4 */
  346. # define M_1_PI        0.31830988618379067154    /* 1/pi */
  347. # define M_2_PI        0.63661977236758134308    /* 2/pi */
  348. # define M_2_SQRTPI    1.12837916709551257390    /* 2/sqrt(pi) */
  349. # define M_SQRT2    1.41421356237309504880    /* sqrt(2) */
  350. # define M_SQRT1_2    0.70710678118654752440    /* 1/sqrt(2) */
  351. #endif
  352.  
  353. /* The above constants are not adequate for computation using `long double's.
  354.    Therefore we provide as an extension constants with similar names as a
  355.    GNU extension.  Provide enough digits for the 128-bit IEEE quad.  */
  356. #ifdef __USE_GNU
  357. # define M_El        2.7182818284590452353602874713526625L  /* e */
  358. # define M_LOG2El    1.4426950408889634073599246810018921L  /* log_2 e */
  359. # define M_LOG10El    0.4342944819032518276511289189166051L  /* log_10 e */
  360. # define M_LN2l        0.6931471805599453094172321214581766L  /* log_e 2 */
  361. # define M_LN10l    2.3025850929940456840179914546843642L  /* log_e 10 */
  362. # define M_PIl        3.1415926535897932384626433832795029L  /* pi */
  363. # define M_PI_2l    1.5707963267948966192313216916397514L  /* pi/2 */
  364. # define M_PI_4l    0.7853981633974483096156608458198757L  /* pi/4 */
  365. # define M_1_PIl    0.3183098861837906715377675267450287L  /* 1/pi */
  366. # define M_2_PIl    0.6366197723675813430755350534900574L  /* 2/pi */
  367. # define M_2_SQRTPIl    1.1283791670955125738961589031215452L  /* 2/sqrt(pi) */
  368. # define M_SQRT2l    1.4142135623730950488016887242096981L  /* sqrt(2) */
  369. # define M_SQRT1_2l    0.7071067811865475244008443621048490L  /* 1/sqrt(2) */
  370. #endif
  371.  
  372.  
  373. /* When compiling in strict ISO C compatible mode we must not use the
  374.    inline functions since they, among other things, do not set the
  375.    `errno' variable correctly.  */
  376. #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
  377. # define __NO_MATH_INLINES    1
  378. #endif
  379.  
  380. /* Get machine-dependent inline versions (if there are any).  */
  381. #ifdef __USE_EXTERN_INLINES
  382. # include <bits/mathinline.h>
  383. #endif
  384.  
  385.  
  386. #if __USE_ISOC99
  387. /* ISO C99 defines some macros to compare number while taking care
  388.    for unordered numbers.  Since many FPUs provide special
  389.    instructions to support these operations and these tests are
  390.    defined in <bits/mathinline.h>, we define the generic macros at
  391.    this late point and only if they are not defined yet.  */
  392.  
  393. /* Return nonzero value if X is greater than Y.  */
  394. # ifndef isgreater
  395. #  ifdef __GNUC__
  396. #   define isgreater(x, y) \
  397.   (__extension__                                  \
  398.    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                  \
  399.       !isunordered (__x, __y) && __x > __y; }))
  400. #  else
  401. #   define isgreater(x, y) ((x) __greater (y))
  402. #  endif
  403. # endif
  404.  
  405. /* Return nonzero value if X is greater than or equal to Y.  */
  406. # ifndef isgreaterequal
  407. #  ifdef __GNUC__
  408. #   define isgreaterequal(x, y) \
  409.   (__extension__                                  \
  410.    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                  \
  411.       !isunordered (__x, __y) && __x >= __y; }))
  412. #  else
  413. #   define isgreaterequal(x, y) ((x) __greaterequal (y))
  414. #  endif
  415. # endif
  416.  
  417. /* Return nonzero value if X is less than Y.  */
  418. # ifndef isless
  419. #  ifdef __GNUC__
  420. #   define isless(x, y) \
  421.   (__extension__                                  \
  422.    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                  \
  423.       !isunordered (__x, __y) && __x < __y; }))
  424. #  else
  425. #   define isless(x, y) ((x) __less (y))
  426. #  endif
  427. # endif
  428.  
  429. /* Return nonzero value if X is less than or equal to Y.  */
  430. # ifndef islessequal
  431. #  ifdef __GNUC__
  432. #   define islessequal(x, y) \
  433.   (__extension__                                  \
  434.    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                  \
  435.       !isunordered (__x, __y) && __x <= __y; }))
  436. #  else
  437. #   define islessequal(x, y) ((x) __lessequal (y))
  438. #  endif
  439. # endif
  440.  
  441. /* Return nonzero value if either X is less than Y or Y is less than X.  */
  442. # ifndef islessgreater
  443. #  ifdef __GNUC__
  444. #   define islessgreater(x, y) \
  445.   (__extension__                                  \
  446.    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                  \
  447.       !isunordered (__x, __y) && (__x < __y || __y < __x); }))
  448. #  else
  449. #   define islessgreater(x, y) ((x) __lessgreater (y))
  450. #  endif
  451. # endif
  452.  
  453. /* Return nonzero value if arguments are unordered.  */
  454. # ifndef isunordered
  455. #  ifdef __GNUC__
  456. #   define isunordered(u, v) \
  457.   (__extension__                                  \
  458.    ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v);                  \
  459.       fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
  460. #  else
  461. #   define isunordered(u, v) ((x) __unordered (y))
  462. #  endif
  463. # endif
  464.  
  465. #endif
  466.  
  467. __END_DECLS
  468.  
  469.  
  470. #endif /* math.h  */
  471.