rtai-core/include/rtai_math.h

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

Generated on Sat Jul 24 19:36:03 2004 for RTAI API by doxygen 1.3.4