Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <math.h>
  2. #include <errno.h>
  3.  
  4.  
  5. #define IBMPC 1
  6. #define ANSIPROT 1
  7. #define MINUSZERO 1
  8. #define INFINITIES 1
  9. #define NANS 1
  10. #define DENORMAL 1
  11. #define VOLATILE
  12. #define mtherr(fname, code)
  13. #define XPD 0,
  14.  
  15. //#define _CEPHES_USE_ERRNO
  16.  
  17. #ifdef _CEPHES_USE_ERRNO
  18. #define _SET_ERRNO(x) errno = (x)
  19. #else
  20. #define _SET_ERRNO(x)
  21. #endif
  22.  
  23. /* constants used by cephes functions */
  24.  
  25. /* double */
  26. #define MAXNUM  1.7976931348623158E308
  27. #define MAXLOG  7.09782712893383996843E2
  28. #define MINLOG  -7.08396418532264106224E2
  29. #define LOGE2   6.93147180559945309417E-1
  30. #define LOG2E   1.44269504088896340736
  31. #define PI      3.14159265358979323846
  32. #define PIO2    1.57079632679489661923
  33. #define PIO4    7.85398163397448309616E-1
  34.  
  35. #define NEGZERO (-0.0)
  36. #undef NAN
  37. #undef INFINITY
  38. #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
  39. #define INFINITY __builtin_huge_val()
  40. #define NAN __builtin_nan("")
  41. #else
  42. extern double __INF;
  43. #define INFINITY (__INF)
  44. extern double __QNAN;
  45. #define NAN (__QNAN)
  46. #endif
  47.  
  48. /*long double*/
  49. #define MAXNUML 1.189731495357231765021263853E4932L
  50. #define MAXLOGL 1.1356523406294143949492E4L
  51. #define MINLOGL -1.13994985314888605586758E4L
  52. #define LOGE2L  6.9314718055994530941723E-1L
  53. #define LOG2EL  1.4426950408889634073599E0L
  54. #define PIL     3.1415926535897932384626L
  55. #define PIO2L   1.5707963267948966192313L
  56. #define PIO4L   7.8539816339744830961566E-1L
  57.  
  58. #define isfinitel isfinite
  59. #define isinfl isinf
  60. #define isnanl isnan
  61. #define signbitl signbit
  62.  
  63. #define NEGZEROL (-0.0L)
  64.  
  65. #undef NANL
  66. #undef INFINITYL
  67. #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
  68. #define INFINITYL __builtin_huge_vall()
  69. #define NANL __builtin_nanl("")
  70. #else
  71. extern long double __INFL;
  72. #define INFINITYL (__INFL)
  73. extern long double __QNANL;
  74. #define NANL (__QNANL)
  75. #endif
  76.  
  77. /* float */
  78.  
  79. #define MAXNUMF 3.4028234663852885981170418348451692544e38F
  80. #define MAXLOGF 88.72283905206835F
  81. #define MINLOGF -103.278929903431851103F /* log(2^-149) */
  82. #define LOG2EF  1.44269504088896341F
  83. #define LOGE2F  0.693147180559945309F
  84. #define PIF     3.141592653589793238F
  85. #define PIO2F   1.5707963267948966192F
  86. #define PIO4F   0.7853981633974483096F
  87.  
  88. #define isfinitef isfinite
  89. #define isinff isinf
  90. #define isnanf isnan
  91. #define signbitf signbit
  92.  
  93. #define NEGZEROF (-0.0F)
  94.  
  95. #undef NANF
  96. #undef INFINITYF
  97. #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
  98. #define INFINITYF __builtin_huge_valf()
  99. #define NANF __builtin_nanf("")
  100. #else
  101. extern float __INFF;
  102. #define INFINITYF (__INFF)
  103. extern float __QNANF;
  104. #define NANF (__QNANF)
  105. #endif
  106.  
  107.  
  108. /* double */
  109.  
  110. /*
  111. Cephes Math Library Release 2.2:  July, 1992
  112. Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
  113. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  114. */
  115.  
  116.  
  117. /*                                                      polevl.c
  118.  *                                                      p1evl.c
  119.  *
  120.  *      Evaluate polynomial
  121.  *
  122.  *
  123.  *
  124.  * SYNOPSIS:
  125.  *
  126.  * int N;
  127.  * double x, y, coef[N+1], polevl[];
  128.  *
  129.  * y = polevl( x, coef, N );
  130.  *
  131.  *
  132.  *
  133.  * DESCRIPTION:
  134.  *
  135.  * Evaluates polynomial of degree N:
  136.  *
  137.  *                     2          N
  138.  * y  =  C  + C x + C x  +...+ C x
  139.  *        0    1     2          N
  140.  *
  141.  * Coefficients are stored in reverse order:
  142.  *
  143.  * coef[0] = C  , ..., coef[N] = C  .
  144.  *            N                   0
  145.  *
  146.  *  The function p1evl() assumes that coef[N] = 1.0 and is
  147.  * omitted from the array.  Its calling arguments are
  148.  * otherwise the same as polevl().
  149.  *
  150.  *
  151.  * SPEED:
  152.  *
  153.  * In the interest of speed, there are no checks for out
  154.  * of bounds arithmetic.  This routine is used by most of
  155.  * the functions in the library.  Depending on available
  156.  * equipment features, the user may wish to rewrite the
  157.  * program in microcode or assembly language.
  158.  *
  159.  */
  160.  
  161. /* Polynomial evaluator:
  162.  *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
  163.  */
  164. static  __inline__ double polevl( x, p, n )
  165. double x;
  166. const void *p;
  167. int n;
  168. {
  169. register double y;
  170. register double *P = (double *)p;
  171.  
  172. y = *P++;
  173. do
  174.         {
  175.         y = y * x + *P++;
  176.         }
  177. while( --n );
  178. return(y);
  179. }
  180.  
  181.  
  182.  
  183. /* Polynomial evaluator:
  184.  *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
  185.  */
  186. static __inline__  double p1evl( x, p, n )
  187. double x;
  188. const void *p;
  189. int n;
  190. {
  191. register double y;
  192. register double *P = (double *)p;
  193.  
  194. n -= 1;
  195. y = x + *P++;
  196. do
  197.         {
  198.         y = y * x + *P++;
  199.         }
  200. while( --n );
  201. return( y );
  202. }
  203.  
  204.  
  205. /* long double */
  206. /*
  207. Cephes Math Library Release 2.2:  July, 1992
  208. Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
  209. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  210. */
  211.  
  212.  
  213. /*                                                      polevll.c
  214.  *                                                      p1evll.c
  215.  *
  216.  *      Evaluate polynomial
  217.  *
  218.  *
  219.  *
  220.  * SYNOPSIS:
  221.  *
  222.  * int N;
  223.  * long double x, y, coef[N+1], polevl[];
  224.  *
  225.  * y = polevll( x, coef, N );
  226.  *
  227.  *
  228.  *
  229.  * DESCRIPTION:
  230.  *
  231.  * Evaluates polynomial of degree N:
  232.  *
  233.  *                     2          N
  234.  * y  =  C  + C x + C x  +...+ C x
  235.  *        0    1     2          N
  236.  *
  237.  * Coefficients are stored in reverse order:
  238.  *
  239.  * coef[0] = C  , ..., coef[N] = C  .
  240.  *            N                   0
  241.  *
  242.  *  The function p1evll() assumes that coef[N] = 1.0 and is
  243.  * omitted from the array.  Its calling arguments are
  244.  * otherwise the same as polevll().
  245.  *
  246.  *
  247.  * SPEED:
  248.  *
  249.  * In the interest of speed, there are no checks for out
  250.  * of bounds arithmetic.  This routine is used by most of
  251.  * the functions in the library.  Depending on available
  252.  * equipment features, the user may wish to rewrite the
  253.  * program in microcode or assembly language.
  254.  *
  255.  */
  256.  
  257. /* Polynomial evaluator:
  258.  *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
  259.  */
  260. static  __inline__ long double polevll( x, p, n )
  261. long double x;
  262. const void *p;
  263. int n;
  264. {
  265. register long double y;
  266. register long double *P = (long double *)p;
  267.  
  268. y = *P++;
  269. do
  270.         {
  271.         y = y * x + *P++;
  272.         }
  273. while( --n );
  274. return(y);
  275. }
  276.  
  277.  
  278.  
  279. /* Polynomial evaluator:
  280.  *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
  281.  */
  282. static __inline__ long double p1evll( x, p, n )
  283. long double x;
  284. const void *p;
  285. int n;
  286. {
  287. register long double y;
  288. register long double *P = (long double *)p;
  289.  
  290. n -= 1;
  291. y = x + *P++;
  292. do
  293.         {
  294.         y = y * x + *P++;
  295.         }
  296. while( --n );
  297. return( y );
  298. }
  299.  
  300. /* Float version */
  301.  
  302. /*                                                      polevlf.c
  303.  *                                                      p1evlf.c
  304.  *
  305.  *      Evaluate polynomial
  306.  *
  307.  *
  308.  *
  309.  * SYNOPSIS:
  310.  *
  311.  * int N;
  312.  * float x, y, coef[N+1], polevlf[];
  313.  *
  314.  * y = polevlf( x, coef, N );
  315.  *
  316.  *
  317.  *
  318.  * DESCRIPTION:
  319.  *
  320.  * Evaluates polynomial of degree N:
  321.  *
  322.  *                     2          N
  323.  * y  =  C  + C x + C x  +...+ C x
  324.  *        0    1     2          N
  325.  *
  326.  * Coefficients are stored in reverse order:
  327.  *
  328.  * coef[0] = C  , ..., coef[N] = C  .
  329.  *            N                   0
  330.  *
  331.  *  The function p1evl() assumes that coef[N] = 1.0 and is
  332.  * omitted from the array.  Its calling arguments are
  333.  * otherwise the same as polevl().
  334.  *
  335.  *
  336.  * SPEED:
  337.  *
  338.  * In the interest of speed, there are no checks for out
  339.  * of bounds arithmetic.  This routine is used by most of
  340.  * the functions in the library.  Depending on available
  341.  * equipment features, the user may wish to rewrite the
  342.  * program in microcode or assembly language.
  343.  *
  344.  */
  345.  
  346. /*
  347. Cephes Math Library Release 2.1:  December, 1988
  348. Copyright 1984, 1987, 1988 by Stephen L. Moshier
  349. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  350. */
  351.  
  352. static __inline__ float polevlf(float x, const float* coef, int N )
  353. {
  354. float ans;
  355. float *p;
  356. int i;
  357.  
  358. p = (float*)coef;
  359. ans = *p++;
  360.  
  361. /*
  362. for( i=0; i<N; i++ )
  363.         ans = ans * x  +  *p++;
  364. */
  365.  
  366. i = N;
  367. do
  368.         ans = ans * x  +  *p++;
  369. while( --i );
  370.  
  371. return( ans );
  372. }
  373.  
  374. /*                                                      p1evl() */
  375. /*                                          N
  376.  * Evaluate polynomial when coefficient of x  is 1.0.
  377.  * Otherwise same as polevl.
  378.  */
  379.  
  380. static __inline__ float p1evlf( float x, const float *coef, int N )
  381. {
  382. float ans;
  383. float *p;
  384. int i;
  385.  
  386. p = (float*)coef;
  387. ans = x + *p++;
  388. i = N-1;
  389.  
  390. do
  391.         ans = ans * x  + *p++;
  392. while( --i );
  393.  
  394. return( ans );
  395. }
  396.