home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / c / cephes.arc / MTHUTL.C < prev    next >
Encoding:
Text File  |  1987-01-03  |  3.9 KB  |  168 lines

  1. /*                            mthutl.c
  2.  *
  3.  *    Utilities for Cephes Math Library
  4.  *
  5.  *
  6.  *
  7.  *
  8.  * DESCRIPTION:
  9.  *
  10.  * This file is a concatenation of several modules from the
  11.  * Cephes Math Library.  Many of the math routines use some
  12.  * of the constants and subroutines found in this file.
  13.  *
  14.  *
  15.  * NOTES NOT MENTIONED ELSEWHERE:
  16.  *
  17.  * The math routines in this package assume that your computer
  18.  * has IBM/DEC style double precision numbers, with an 8 bit
  19.  * exponent and 56 bit mantissa.  They will NOT work without
  20.  * modification if your computer uses IEEE style double precision
  21.  * numbers.
  22.  *
  23.  */
  24.  
  25. /*                            const.c
  26. Cephes Math Library Release 1.0:  July, 1984
  27. Copyright 1984 by Stephen L. Moshier
  28. Contributed to BIX for personal, non-commercial use only.
  29. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  30. */
  31. /* log(2**127) = 88.029691931113054295988 */
  32. extern short MAXLOG[4] = {041660,007463,0143742,025733};
  33.  
  34. /* log(2**-128) = -88.72283911167299960540 */
  35. extern short MINLOG[4] = {0141661,071027,0173721,0147572};
  36.  
  37. /* 2**127 = 1.701411834604692317316873e38 */
  38. extern short MAXNUM[4] = {077777,0177777,0177777,0177777};
  39.  
  40. /* pi = 3.14159265358979323846 */
  41. extern short PI[4] = {040511,007732,0121041,064302};
  42.  
  43. /* pi/2 = 1.57079632679489661923 */
  44. extern short PIO2[4] = {040311,007732,0121041,064302};
  45.  
  46. /* pi/4 = 0.78539816339744830962 */
  47. extern short PIO4[4] = {040111,007732,0121041,064302};
  48.  
  49. /* sqrt(2) = 1.41421356237309504880 */
  50. extern short SQRT2[4] = {040265,002363,031771,0157145};
  51.  
  52. /* sqrt(2)/2 = 0.70710678118654752440 */
  53. extern short SQRTH[4] = {040065,002363,031771,0157144};
  54.  
  55. /* 1/log(2) = 1.4426950408889634073599 */
  56. extern short LOG2E[4] = {040270,0125073,024534,013761};
  57.  
  58. /*                            const.c 2 */
  59.  
  60. /* sqrt( 2/pi ) = 0.79788456080286535587989 */
  61. extern short SQ2OPI[4] = {040114,041051,0117241,0131204};
  62.  
  63. /* log(2) = 0.69314718055994530941 */
  64. extern short LOGE2[4] = {040061,071027,0173721,0147572};
  65.  
  66. /* log(2)/2 = 0.346573590279972654708 */
  67. extern short LOGSQ2[4] = {037661,071027,0173721,0147572};
  68.  
  69. /* 3*pi/4 = 2.35619449019234492885 */
  70. extern short THPIO4[4] = {040426,0145743,0174631,007222};
  71.  
  72. /* 2/pi =  .63661977236758134307553505 */
  73. extern short TWOOPI[4] = {040042,0174603,067116,042025};
  74.  
  75. static char x[] =
  76. "Cephes Math Library by Stephen L. Moshier";
  77. /*                            polevl.c
  78.  *                            p1evl.c
  79.  *
  80.  *    Evaluate polynomial
  81.  *
  82.  *
  83.  *
  84.  * SYNOPSIS:
  85.  *
  86.  * int N;
  87.  * double x, y, coef[N+1], polevl[];
  88.  *
  89.  * y = polevl( C, x, N );
  90.  *
  91.  *
  92.  *
  93.  * DESCRIPTION:
  94.  *
  95.  * Evaluates polynomial of degree N:
  96.  *
  97.  *                     2          N
  98.  * y  =  C  + C x + C x  +...+ C x
  99.  *        0    1     2          N
  100.  *
  101.  * Coefficients are stored in reverse order:
  102.  *
  103.  * coef[0] = C  , ..., coef[N] = C  .
  104.  *            N                   0
  105.  *
  106.  *  The function p1evl() assumes that coef[N] = 1.0 and is
  107.  * omitted from the array.  Its calling arguments are
  108.  * otherwise the same as polevl().
  109.  *
  110.  *
  111.  * SPEED:
  112.  *
  113.  * In the interest of speed, there are no checks for out
  114.  * of bounds arithmetic.  This routine is used by most of
  115.  * the functions in the library.  Depending on available
  116.  * equipment features, the user may wish to rewrite the
  117.  * program in microcode or assembly language.
  118.  *
  119.  */
  120. /*                            polevl.c */
  121.  
  122.  
  123. double polevl( x, coef, N )
  124. double x;
  125. double coef[];
  126. int N;
  127. {
  128. double ans;
  129. short i;
  130. register double *p;
  131.  
  132. p = coef;
  133. ans = 0.0;
  134. i = N+1;
  135.  
  136. do
  137.     ans = ans * x  +  *p++;
  138. while( --i );
  139.  
  140. return( ans );
  141. }
  142.  
  143. /*                            p1evl()    */
  144. /*                                          N
  145.  * Evaluate polynomial when coefficient of x  is 1.0.
  146.  * Otherwise same as polevl.
  147.  */
  148.  
  149. double p1evl( x, coef, N )
  150. double x;
  151. double coef[];
  152. int N;
  153. {
  154. double ans;
  155. register double *p;
  156. short i;
  157.  
  158. p = coef;
  159. ans = x + *p++;
  160. i = N-1;
  161.  
  162. do
  163.     ans = ans * x  + *p++;
  164. while( --i );
  165.  
  166. return( ans );
  167. }
  168.