home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / libm-src.lha / src / amiga / libm / common / trig.h < prev   
C/C++ Source or Header  |  1993-09-23  |  9KB  |  217 lines

  1. /*
  2.  * Copyright (c) 1987 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)trig.h    5.6 (Berkeley) 10/9/90
  34.  */
  35.  
  36. #include "mathimpl.h"
  37.  
  38. vc(thresh, 2.6117239648121182150E-1 ,b863,3f85,6ea0,6b02, -1, .85B8636B026EA0)
  39. vc(PIo4,   7.8539816339744830676E-1 ,0fda,4049,68c2,a221,  0, .C90FDAA22168C2)
  40. vc(PIo2,   1.5707963267948966135E0  ,0fda,40c9,68c2,a221,  1, .C90FDAA22168C2)
  41. vc(PI3o4,  2.3561944901923449203E0  ,cbe3,4116,0e92,f999,  2, .96CBE3F9990E92)
  42. #undef PI
  43. vc(PI,     3.1415926535897932270E0  ,0fda,4149,68c2,a221,  2, .C90FDAA22168C2)
  44. vc(PI2,    6.2831853071795864540E0  ,0fda,41c9,68c2,a221,  3, .C90FDAA22168C2)
  45.  
  46. ic(thresh, 2.6117239648121182150E-1 , -2, 1.0B70C6D604DD4)
  47. ic(PIo4,   7.8539816339744827900E-1 , -1, 1.921FB54442D18)
  48. ic(PIo2,   1.5707963267948965580E0  ,  0, 1.921FB54442D18)
  49. ic(PI3o4,  2.3561944901923448370E0  ,  1, 1.2D97C7F3321D2)
  50. ic(PI,     3.1415926535897931160E0  ,  1, 1.921FB54442D18)
  51. ic(PI2,    6.2831853071795862320E0  ,  2, 1.921FB54442D18)
  52.  
  53. #ifdef vccast
  54. #define    thresh    vccast(thresh)
  55. #define    PIo4    vccast(PIo4)
  56. #define    PIo2    vccast(PIo2)
  57. #define    PI3o4    vccast(PI3o4)
  58. #define    PI    vccast(PI)
  59. #define    PI2    vccast(PI2)
  60. #endif
  61.  
  62. #ifdef national
  63. static long fmaxx[]    = { 0xffffffff, 0x7fefffff};
  64. #define   fmax    (*(double*)fmaxx)
  65. #endif    /* national */
  66.  
  67. static const double
  68.     zero = 0,
  69.     one = 1,
  70.     negone = -1,
  71.     half = 1.0/2.0, 
  72.     small = 1E-10,    /* 1+small**2 == 1; better values for small:
  73.              *        small    = 1.5E-9 for VAX D
  74.              *            = 1.2E-8 for IEEE Double
  75.              *            = 2.8E-10 for IEEE Extended
  76.              */
  77.     big = 1E20;    /* big := 1/(small**2) */
  78.  
  79. /* sin__S(x*x) ... re-implemented as a macro
  80.  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
  81.  * STATIC KERNEL FUNCTION OF SIN(X), COS(X), AND TAN(X) 
  82.  * CODED IN C BY K.C. NG, 1/21/85; 
  83.  * REVISED BY K.C. NG on 8/13/85.
  84.  *
  85.  *        sin(x*k) - x
  86.  * RETURN  --------------- on [-PI/4,PI/4] , where k=pi/PI, PI is the rounded
  87.  *                x    
  88.  * value of pi in machine precision:
  89.  *
  90.  *    Decimal:
  91.  *        pi = 3.141592653589793 23846264338327 ..... 
  92.  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
  93.  *    56 bits   PI = 3.141592653589793 227020265 ..... ,  
  94.  *
  95.  *    Hexadecimal:
  96.  *        pi = 3.243F6A8885A308D313198A2E....
  97.  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18
  98.  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    
  99.  *
  100.  * Method:
  101.  *    1. Let z=x*x. Create a polynomial approximation to 
  102.  *        (sin(k*x)-x)/x  =  z*(S0 + S1*z^1 + ... + S5*z^5).
  103.  *    Then
  104.  *      sin__S(x*x) = z*(S0 + S1*z^1 + ... + S5*z^5)
  105.  *
  106.  *    The coefficient S's are obtained by a special Remez algorithm.
  107.  *
  108.  * Accuracy:
  109.  *    In the absence of rounding error, the approximation has absolute error 
  110.  *    less than 2**(-61.11) for VAX D FORMAT, 2**(-57.45) for IEEE DOUBLE. 
  111.  *
  112.  * Constants:
  113.  * The hexadecimal values are the intended ones for the following constants.
  114.  * The decimal values may be used, provided that the compiler will convert
  115.  * from decimal to binary accurately enough to produce the hexadecimal values
  116.  * shown.
  117.  *
  118.  */
  119.  
  120. vc(S0, -1.6666666666666646660E-1  ,aaaa,bf2a,aa71,aaaa,  -2, -.AAAAAAAAAAAA71)
  121. vc(S1,  8.3333333333297230413E-3  ,8888,3d08,477f,8888,  -6,  .8888888888477F)
  122. vc(S2, -1.9841269838362403710E-4  ,0d00,ba50,1057,cf8a, -12, -.D00D00CF8A1057)
  123. vc(S3,  2.7557318019967078930E-6  ,ef1c,3738,bedc,a326, -18,  .B8EF1CA326BEDC)
  124. vc(S4, -2.5051841873876551398E-8  ,3195,b3d7,e1d3,374c, -25, -.D73195374CE1D3)
  125. vc(S5,  1.6028995389845827653E-10 ,3d9c,3030,cccc,6d26, -32,  .B03D9C6D26CCCC)
  126. vc(S6, -6.2723499671769283121E-13 ,8d0b,ac30,ea82,7561, -40, -.B08D0B7561EA82)
  127.  
  128. ic(S0, -1.6666666666666463126E-1  ,  -3, -1.555555555550C)
  129. ic(S1,  8.3333333332992771264E-3  ,  -7,  1.111111110C461)
  130. ic(S2, -1.9841269816180999116E-4  , -13, -1.A01A019746345)
  131. ic(S3,  2.7557309793219876880E-6  , -19,  1.71DE3209CDCD9)
  132. ic(S4, -2.5050225177523807003E-8  , -26, -1.AE5C0E319A4EF)
  133. ic(S5,  1.5868926979889205164E-10 , -33,  1.5CF61DF672B13)
  134.  
  135. #ifdef vccast
  136. #define    S0    vccast(S0)
  137. #define    S1    vccast(S1)
  138. #define    S2    vccast(S2)
  139. #define    S3    vccast(S3)
  140. #define    S4    vccast(S4)
  141. #define    S5    vccast(S5)
  142. #define    S6    vccast(S6)
  143. #endif
  144.  
  145. #if defined(vax)||defined(tahoe)
  146. #  define    sin__S(z)    (z*(S0+z*(S1+z*(S2+z*(S3+z*(S4+z*(S5+z*S6)))))))
  147. #else     /* defined(vax)||defined(tahoe) */
  148. #  define    sin__S(z)    (z*(S0+z*(S1+z*(S2+z*(S3+z*(S4+z*S5))))))
  149. #endif     /* defined(vax)||defined(tahoe) */
  150.  
  151. /* cos__C(x*x) ... re-implemented as a macro
  152.  * DOUBLE PRECISION (VAX D FORMAT 56 BITS, IEEE DOUBLE 53 BITS)
  153.  * STATIC KERNEL FUNCTION OF SIN(X), COS(X), AND TAN(X) 
  154.  * CODED IN C BY K.C. NG, 1/21/85; 
  155.  * REVISED BY K.C. NG on 8/13/85.
  156.  *
  157.  *                   x*x    
  158.  * RETURN   cos(k*x) - 1 + ----- on [-PI/4,PI/4],  where k = pi/PI,
  159.  *                   2    
  160.  * PI is the rounded value of pi in machine precision :
  161.  *
  162.  *    Decimal:
  163.  *        pi = 3.141592653589793 23846264338327 ..... 
  164.  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
  165.  *    56 bits   PI = 3.141592653589793 227020265 ..... ,  
  166.  *
  167.  *    Hexadecimal:
  168.  *        pi = 3.243F6A8885A308D313198A2E....
  169.  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18
  170.  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    
  171.  *
  172.  *
  173.  * Method:
  174.  *    1. Let z=x*x. Create a polynomial approximation to 
  175.  *        cos(k*x)-1+z/2  =  z*z*(C0 + C1*z^1 + ... + C5*z^5)
  176.  *    then
  177.  *      cos__C(z) =  z*z*(C0 + C1*z^1 + ... + C5*z^5)
  178.  *
  179.  *    The coefficient C's are obtained by a special Remez algorithm.
  180.  *
  181.  * Accuracy:
  182.  *    In the absence of rounding error, the approximation has absolute error 
  183.  *    less than 2**(-64) for VAX D FORMAT, 2**(-58.3) for IEEE DOUBLE. 
  184.  *    
  185.  *
  186.  * Constants:
  187.  * The hexadecimal values are the intended ones for the following constants.
  188.  * The decimal values may be used, provided that the compiler will convert
  189.  * from decimal to binary accurately enough to produce the hexadecimal values
  190.  * shown.
  191.  */
  192.  
  193. vc(C0,  4.1666666666666504759E-2  ,aaaa,3e2a,a9f0,aaaa,  -4,  .AAAAAAAAAAA9F0)
  194. vc(C1, -1.3888888888865302059E-3  ,0b60,bbb6,0cca,b60a,  -9, -.B60B60B60A0CCA)
  195. vc(C2,  2.4801587285601038265E-5  ,0d00,38d0,098f,cdcd, -15,  .D00D00CDCD098F)
  196. vc(C3, -2.7557313470902390219E-7  ,f27b,b593,e805,b593, -21, -.93F27BB593E805)
  197. vc(C4,  2.0875623401082232009E-9  ,74c8,320f,3ff0,fa1e, -28,  .8F74C8FA1E3FF0)
  198. vc(C5, -1.1355178117642986178E-11 ,c32d,ae47,5a63,0a5c, -36, -.C7C32D0A5C5A63)
  199.  
  200. ic(C0,  4.1666666666666504759E-2  ,  -5,  1.555555555553E)
  201. ic(C1, -1.3888888888865301516E-3  , -10, -1.6C16C16C14199)
  202. ic(C2,  2.4801587269650015769E-5  , -16,  1.A01A01971CAEB)
  203. ic(C3, -2.7557304623183959811E-7  , -22, -1.27E4F1314AD1A)
  204. ic(C4,  2.0873958177697780076E-9  , -29,  1.1EE3B60DDDC8C)
  205. ic(C5, -1.1250289076471311557E-11 , -37, -1.8BD5986B2A52E)
  206.  
  207. #ifdef vccast
  208. #define    C0    vccast(C0)
  209. #define    C1    vccast(C1)
  210. #define    C2    vccast(C2)
  211. #define    C3    vccast(C3)
  212. #define    C4    vccast(C4)
  213. #define    C5    vccast(C5)
  214. #endif
  215.  
  216. #define cos__C(z)    (z*z*(C0+z*(C1+z*(C2+z*(C3+z*(C4+z*C5))))))
  217.