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