base/include/rtai_math.h

Go to the documentation of this file.
00001 /*
00002  * Declarations for math functions.
00003  * Copyright (C) 1991,92,93,95,96,97,98,99,2001 Free Software Foundation, Inc.
00004  * This file is part of the GNU C Library.
00005  *
00006  * The GNU C Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * The GNU C Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with the GNU C Library; if not, write to the Free
00018  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307 USA.
00020  */
00021 
00022 /*
00023  * ISO C99 Standard: 7.12 Mathematics <math.h>
00024  */
00025 
00026 #ifndef _RTAI_MATH_H
00027 #define _RTAI_MATH_H    1
00028 #define _MATH_H         1
00029 
00030 #include <rtai_types.h>
00031 #ifdef __attribute_pure__
00032 #undef __attribute_pure__
00033 #endif
00034 #ifdef __attribute_used__
00035 #undef __attribute_used__
00036 #endif
00037 #include <features.h>
00038 
00039 __BEGIN_DECLS
00040 
00041 /* Get machine-dependent HUGE_VAL value (returned on overflow).
00042    On all IEEE754 machines, this is +Infinity.  */
00043 #include <bits/huge_val.h>
00044 
00045 /* Get machine-dependent NAN value (returned for some domain errors).  */
00046 #ifdef   __USE_ISOC99
00047 # include <bits/nan.h>
00048 #endif
00049 /* Get general and ISO C99 specific information.  */
00050 #include <bits/mathdef.h>
00051 
00052 
00053 /* The file <bits/mathcalls.h> contains the prototypes for all the
00054    actual math functions.  These macros are used for those prototypes,
00055    so we can easily declare each function as both `name' and `__name',
00056    and can declare the float versions `namef' and `__namef'.  */
00057 
00058 #define __MATHCALL(function,suffix, args)   \
00059   __MATHDECL (_Mdouble_,function,suffix, args)
00060 #define __MATHDECL(type, function,suffix, args) \
00061   __MATHDECL_1(type, function,suffix, args); \
00062   __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
00063 #define __MATHCALLX(function,suffix, args, attrib)  \
00064   __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
00065 #define __MATHDECLX(type, function,suffix, args, attrib) \
00066   __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
00067   __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
00068 #define __MATHDECL_1(type, function,suffix, args) \
00069   extern type __MATH_PRECNAME(function,suffix) args __THROW
00070 
00071 #define _Mdouble_       double
00072 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
00073 // added for gcc-3.2
00074 #define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
00075 #define _Mdouble_END_NAMESPACE   __END_NAMESPACE_STD
00076 // end added for gcc-3.2
00077 #include <bits/mathcalls.h>
00078 #undef  _Mdouble_
00079 // added for gcc-3.2
00080 #undef _Mdouble_BEGIN_NAMESPACE
00081 #undef _Mdouble_END_NAMESPACE
00082 // end added for gcc-3.2
00083 #undef  __MATH_PRECNAME
00084 
00085 #if defined __USE_MISC || defined __USE_ISOC99
00086 
00087 
00088 /* Include the file of declarations again, this time using `float'
00089    instead of `double' and appending f to each function name.  */
00090 
00091 # ifndef _Mfloat_
00092 #  define _Mfloat_      float
00093 # endif
00094 # define _Mdouble_      _Mfloat_
00095 # ifdef __STDC__
00096 #  define __MATH_PRECNAME(name,r) name##f##r
00097 # else
00098 #  define __MATH_PRECNAME(name,r) name/**/f/**/r
00099 # endif
00100 // added for gcc-3.2
00101 #define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
00102 #define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
00103 // end added for gcc-3.2
00104 # include <bits/mathcalls.h>
00105 # undef _Mdouble_
00106 // added for gcc-3.2
00107 # undef _Mdouble_BEGIN_NAMESPACE
00108 # undef _Mdouble_END_NAMESPACE
00109 // end added for gcc-3.2
00110 # undef __MATH_PRECNAME
00111 
00112 # if (__STDC__ - 0 || __GNUC__ - 0) && !defined __NO_LONG_DOUBLE_MATH
00113 /* Include the file of declarations again, this time using `long double'
00114    instead of `double' and appending l to each function name.  */
00115 
00116 #  ifndef _Mlong_double_
00117 #   define _Mlong_double_   long double
00118 #  endif
00119 #  define _Mdouble_         _Mlong_double_
00120 #  ifdef __STDC__
00121 #   define __MATH_PRECNAME(name,r) name##l##r
00122 #  else
00123 #   define __MATH_PRECNAME(name,r) name/**/l/**/r
00124 #  endif
00125 // added for gcc-3.2
00126 #define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_C99
00127 #define _Mdouble_END_NAMESPACE   __END_NAMESPACE_C99
00128 // end added for gcc-3.2
00129 #  include <bits/mathcalls.h>
00130 #  undef _Mdouble_
00131 // added for gcc-3.2
00132 # undef _Mdouble_BEGIN_NAMESPACE
00133 # undef _Mdouble_END_NAMESPACE 
00134 // end added for gcc-3.2
00135 #  undef __MATH_PRECNAME
00136 
00137 # endif /* __STDC__ || __GNUC__ */
00138 
00139 #endif  /* Use misc or ISO C99.  */
00140 #undef  __MATHDECL_1
00141 #undef  __MATHDECL
00142 #undef  __MATHCALL
00143 
00144 
00145 #if defined __USE_MISC || defined __USE_XOPEN
00146 /* This variable is used by `gamma' and `lgamma'.  */
00147 extern int signgam;
00148 #endif
00149 
00150 
00151 /* ISO C99 defines some generic macros which work on any data type.  */
00152 #if defined(__USE_ISOC99) && __USE_ISOC99
00153 
00154 /* Get the architecture specific values describing the floating-point
00155    evaluation.  The following symbols will get defined:
00156 
00157     float_t floating-point type at least as wide as `float' used
00158         to evaluate `float' expressions
00159     double_t    floating-point type at least as wide as `double' used
00160         to evaluate `double' expressions
00161 
00162     FLT_EVAL_METHOD
00163         Defined to
00164           0 if `float_t' is `float' and `double_t' is `double'
00165           1 if `float_t' and `double_t' are `double'
00166           2 if `float_t' and `double_t' are `long double'
00167           else  `float_t' and `double_t' are unspecified
00168 
00169     INFINITY    representation of the infinity value of type `float'
00170 
00171     FP_FAST_FMA
00172     FP_FAST_FMAF
00173     FP_FAST_FMAL
00174         If defined it indicates that the `fma' function
00175         generally executes about as fast as a multiply and an add.
00176         This macro is defined only iff the `fma' function is
00177         implemented directly with a hardware multiply-add instructions.
00178 
00179     FP_ILOGB0   Expands to a value returned by `ilogb (0.0)'.
00180     FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
00181 
00182     DECIMAL_DIG Number of decimal digits supported by conversion between
00183         decimal and all internal floating-point formats.
00184 
00185 */
00186 
00187 /* All floating-point numbers can be put in one of these categories.  */
00188 enum
00189   {
00190     FP_NAN,
00191 # define FP_NAN FP_NAN
00192     FP_INFINITE,
00193 # define FP_INFINITE FP_INFINITE
00194     FP_ZERO,
00195 # define FP_ZERO FP_ZERO
00196     FP_SUBNORMAL,
00197 # define FP_SUBNORMAL FP_SUBNORMAL
00198     FP_NORMAL
00199 # define FP_NORMAL FP_NORMAL
00200   };
00201 
00202 /* Return number of classification appropriate for X.  */
00203 # ifdef __NO_LONG_DOUBLE_MATH
00204 #  define fpclassify(x) \
00205      (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassify (x))
00206 # else
00207 #  define fpclassify(x) \
00208      (sizeof (x) == sizeof (float)                        \
00209       ? __fpclassifyf (x)                             \
00210       : sizeof (x) == sizeof (double)                         \
00211       ? __fpclassify (x) : __fpclassifyl (x))
00212 # endif
00213 
00214 /* Return nonzero value if sign of X is negative.  */
00215 # ifdef __NO_LONG_DOUBLE_MATH
00216 #  define signbit(x) \
00217      (sizeof (x) == sizeof (float) ? __signbitf (x) : __signbit (x))
00218 # else
00219 #  define signbit(x) \
00220      (sizeof (x) == sizeof (float)                        \
00221       ? __signbitf (x)                                \
00222       : sizeof (x) == sizeof (double)                         \
00223       ? __signbit (x) : __signbitl (x))
00224 # endif
00225 
00226 /* Return nonzero value if X is not +-Inf or NaN.  */
00227 # ifdef __NO_LONG_DOUBLE_MATH
00228 #  define isfinite(x) \
00229      (sizeof (x) == sizeof (float) ? __finitef (x) : __finite (x))
00230 # else
00231 #  define isfinite(x) \
00232      (sizeof (x) == sizeof (float)                        \
00233       ? __finitef (x)                                 \
00234       : sizeof (x) == sizeof (double)                         \
00235       ? __finite (x) : __finitel (x))
00236 # endif
00237 
00238 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN.  */
00239 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
00240 
00241 /* Return nonzero value if X is a NaN.  We could use `fpclassify' but
00242    we already have this functions `__isnan' and it is faster.  */
00243 # ifdef __NO_LONG_DOUBLE_MATH
00244 #  define isnan(x) \
00245      (sizeof (x) == sizeof (float) ? __isnanf (x) : __isnan (x))
00246 # else
00247 #  define isnan(x) \
00248      (sizeof (x) == sizeof (float)                        \
00249       ? __isnanf (x)                                  \
00250       : sizeof (x) == sizeof (double)                         \
00251       ? __isnan (x) : __isnanl (x))
00252 # endif
00253 
00254 /* Return nonzero value is X is positive or negative infinity.  */
00255 # ifdef __NO_LONG_DOUBLE_MATH
00256 #  define isinf(x) \
00257      (sizeof (x) == sizeof (float) ? __isinff (x) : __isinf (x))
00258 # else
00259 #  define isinf(x) \
00260      (sizeof (x) == sizeof (float)                        \
00261       ? __isinff (x)                                  \
00262       : sizeof (x) == sizeof (double)                         \
00263       ? __isinf (x) : __isinfl (x))
00264 # endif
00265 
00266 /* Bitmasks for the math_errhandling macro.  */
00267 # define MATH_ERRNO 1   /* errno set by math functions.  */
00268 # define MATH_ERREXCEPT 2   /* Exceptions raised by math functions.  */
00269 
00270 #endif /* Use ISO C99.  */
00271 
00272 #ifdef  __USE_MISC
00273 /* Support for various different standard error handling behaviors.  */
00274 typedef enum
00275 {
00276   _IEEE_ = -1,  /* According to IEEE 754/IEEE 854.  */
00277   _SVID_,   /* According to System V, release 4.  */
00278   _XOPEN_,  /* Nowadays also Unix98.  */
00279   _POSIX_,
00280   _ISOC_    /* Actually this is ISO C99.  */
00281 } _LIB_VERSION_TYPE;
00282 
00283 /* This variable can be changed at run-time to any of the values above to
00284    affect floating point error handling behavior (it may also be necessary
00285    to change the hardware FPU exception settings).  */
00286 extern _LIB_VERSION_TYPE _LIB_VERSION;
00287 #endif
00288 
00289 
00290 #ifdef __USE_SVID
00291 /* In SVID error handling, `matherr' is called with this description
00292    of the exceptional condition.
00293 
00294    We have a problem when using C++ since `exception' is a reserved
00295    name in C++.  */
00296 # ifdef __cplusplus
00297 struct __exception
00298 # else
00299 struct exception
00300 # endif
00301   {
00302     int type;
00303     char *name;
00304     double arg1;
00305     double arg2;
00306     double retval;
00307   };
00308 
00309 # ifdef __cplusplus
00310 extern int matherr (struct __exception *__exc) throw ();
00311 # else
00312 extern int matherr (struct exception *__exc);
00313 # endif
00314 
00315 # define X_TLOSS    1.41484755040568800000e+16
00316 
00317 /* Types of exceptions in the `type' field.  */
00318 # define DOMAIN     1
00319 # define SING       2
00320 # define OVERFLOW   3
00321 # define UNDERFLOW  4
00322 # define TLOSS      5
00323 # define PLOSS      6
00324 
00325 /* SVID mode specifies returning this large value instead of infinity.  */
00326 # define HUGE       3.40282347e+38F
00327 
00328 #else   /* !SVID */
00329 
00330 # ifdef __USE_XOPEN
00331 /* X/Open wants another strange constant.  */
00332 #  define MAXFLOAT  3.40282347e+38F
00333 # endif
00334 
00335 #endif  /* SVID */
00336 
00337 
00338 /* Some useful constants.  */
00339 #if defined __USE_BSD || defined __USE_XOPEN
00340 # define M_E        2.7182818284590452354   /* e */
00341 # define M_LOG2E    1.4426950408889634074   /* log_2 e */
00342 # define M_LOG10E   0.43429448190325182765  /* log_10 e */
00343 # define M_LN2      0.69314718055994530942  /* log_e 2 */
00344 # define M_LN10     2.30258509299404568402  /* log_e 10 */
00345 # define M_PI       3.14159265358979323846  /* pi */
00346 # define M_PI_2     1.57079632679489661923  /* pi/2 */
00347 # define M_PI_4     0.78539816339744830962  /* pi/4 */
00348 # define M_1_PI     0.31830988618379067154  /* 1/pi */
00349 # define M_2_PI     0.63661977236758134308  /* 2/pi */
00350 # define M_2_SQRTPI 1.12837916709551257390  /* 2/sqrt(pi) */
00351 # define M_SQRT2    1.41421356237309504880  /* sqrt(2) */
00352 # define M_SQRT1_2  0.70710678118654752440  /* 1/sqrt(2) */
00353 #endif
00354 
00355 /* The above constants are not adequate for computation using `long double's.
00356    Therefore we provide as an extension constants with similar names as a
00357    GNU extension.  Provide enough digits for the 128-bit IEEE quad.  */
00358 #ifdef __USE_GNU
00359 # define M_El       2.7182818284590452353602874713526625L  /* e */
00360 # define M_LOG2El   1.4426950408889634073599246810018922L  /* log_2 e */
00361 # define M_LOG10El  0.4342944819032518276511289189166051L  /* log_10 e */
00362 # define M_LN2l     0.6931471805599453094172321214581766L  /* log_e 2 */
00363 # define M_LN10l    2.3025850929940456840179914546843642L  /* log_e 10 */
00364 # define M_PIl      3.1415926535897932384626433832795029L  /* pi */
00365 # define M_PI_2l    1.5707963267948966192313216916397514L  /* pi/2 */
00366 # define M_PI_4l    0.7853981633974483096156608458198757L  /* pi/4 */
00367 # define M_1_PIl    0.3183098861837906715377675267450287L  /* 1/pi */
00368 # define M_2_PIl    0.6366197723675813430755350534900574L  /* 2/pi */
00369 # define M_2_SQRTPIl    1.1283791670955125738961589031215452L  /* 2/sqrt(pi) */
00370 # define M_SQRT2l   1.4142135623730950488016887242096981L  /* sqrt(2) */
00371 # define M_SQRT1_2l 0.7071067811865475244008443621048490L  /* 1/sqrt(2) */
00372 #endif
00373 
00374 
00375 /* When compiling in strict ISO C compatible mode we must not use the
00376    inline functions since they, among other things, do not set the
00377    `errno' variable correctly.  */
00378 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
00379 # define __NO_MATH_INLINES  1
00380 #endif
00381 
00382 /* Get machine-dependent inline versions (if there are any).  */
00383 #ifdef __USE_EXTERN_INLINES
00384 # include <bits/mathinline.h>
00385 #endif
00386 
00387 
00388 #if defined(__USE_ISOC99) && __USE_ISOC99
00389 /* ISO C99 defines some macros to compare number while taking care
00390    for unordered numbers.  Since many FPUs provide special
00391    instructions to support these operations and these tests are
00392    defined in <bits/mathinline.h>, we define the generic macros at
00393    this late point and only if they are not defined yet.  */
00394 
00395 /* Return nonzero value if X is greater than Y.  */
00396 # ifndef isgreater
00397 #  define isgreater(x, y) \
00398   (__extension__                                  \
00399    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);               \
00400       !isunordered (__x, __y) && __x > __y; }))
00401 # endif
00402 
00403 /* Return nonzero value if X is greater than or equal to Y.  */
00404 # ifndef isgreaterequal
00405 #  define isgreaterequal(x, y) \
00406   (__extension__                                  \
00407    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);               \
00408       !isunordered (__x, __y) && __x >= __y; }))
00409 # endif
00410 
00411 /* Return nonzero value if X is less than Y.  */
00412 # ifndef isless
00413 #  define isless(x, y) \
00414   (__extension__                                  \
00415    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);               \
00416       !isunordered (__x, __y) && __x < __y; }))
00417 # endif
00418 
00419 /* Return nonzero value if X is less than or equal to Y.  */
00420 # ifndef islessequal
00421 #  define islessequal(x, y) \
00422   (__extension__                                  \
00423    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);               \
00424       !isunordered (__x, __y) && __x <= __y; }))
00425 # endif
00426 
00427 /* Return nonzero value if either X is less than Y or Y is less than X.  */
00428 # ifndef islessgreater
00429 #  define islessgreater(x, y) \
00430   (__extension__                                  \
00431    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);               \
00432       !isunordered (__x, __y) && (__x < __y || __y < __x); }))
00433 # endif
00434 
00435 /* Return nonzero value if arguments are unordered.  */
00436 # ifndef isunordered
00437 #  define isunordered(u, v) \
00438   (__extension__                                  \
00439    ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v);               \
00440       fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
00441 # endif
00442 
00443 #endif
00444 
00445 __END_DECLS
00446 
00447 /* Missing declarations */
00448 
00449 struct complex {
00450     double x;
00451     double y;
00452 };
00453 
00454 double cabs __P((struct complex));
00455 
00456 double gamma_r(double x, int *signgamp); /* wrapper lgamma_r */
00457 
00458 long int rinttol(double x);
00459 
00460 long int roundtol(double x);
00461 
00462 #endif /* !_RTAI_MATH_H  */

Generated on Tue Feb 2 17:46:05 2010 for RTAI API by  doxygen 1.4.7