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