trigP.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:10k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* trigP.h - trigonometric definitions for Berkeley math package */
  2. /* Copyright 1994 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01e,14oct94,ism  fixed syntax error per SPR#3718
  7. 01d,22sep92,rrr  added support for c++
  8. 01c,01jul92,smb  added to clib library.
  9. 01b,04oct91,rrr  passed through the ansification filter
  10.   -fixed #else and #endif
  11.   -changed copyright notice
  12. 01a,14sep90,mcl  adapted from Berkeley.
  13. */
  14. #ifndef __INCtrigPh
  15. #define __INCtrigPh
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*
  20.  * Copyright (c) 1987 Regents of the University of California.
  21.  * All rights reserved.
  22.  *
  23.  * Redistribution and use in source and binary forms are permitted
  24.  * provided that the above copyright notice and this paragraph are
  25.  * duplicated in all such forms and that any documentation,
  26.  * advertising materials, and other materials related to such
  27.  * distribution and use acknowledge that the software was developed
  28.  * by the University of California, Berkeley.  The name of the
  29.  * University may not be used to endorse or promote products derived
  30.  * from this software without specific prior written permission.
  31.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  32.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  33.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  34.  *
  35.  * All recipients should regard themselves as participants in an ongoing
  36.  * research project and hence should feel obligated to report their
  37.  * experiences (good or bad) with these elementary function codes, using
  38.  * the sendbug(8) program, to the authors.
  39.  *
  40.  * @(#)trig.h 5.3 (Berkeley) 6/30/88
  41.  */
  42. #if defined(vax)||defined(tahoe)
  43. #ifdef vax
  44. #define _0x(A,B) 0x/**/A/**/B
  45. #else /* vax */
  46. #define _0x(A,B) 0x/**/B/**/A
  47. #endif /* vax */
  48. /*thresh =  2.6117239648121182150E-1    , Hex  2^ -1   *  .85B8636B026EA0 */
  49. /*PIo4   =  7.8539816339744830676E-1    , Hex  2^  0   *  .C90FDAA22168C2 */
  50. /*PIo2   =  1.5707963267948966135E0     , Hex  2^  1   *  .C90FDAA22168C2 */
  51. /*PI3o4  =  2.3561944901923449203E0     , Hex  2^  2   *  .96CBE3F9990E92 */
  52. /*PI     =  3.1415926535897932270E0     , Hex  2^  2   *  .C90FDAA22168C2 */
  53. /*PI2    =  6.2831853071795864540E0     ; Hex  2^  3   *  .C90FDAA22168C2 */
  54. static long threshx[] = { _0x(b863,3f85), _0x(6ea0,6b02)};
  55. static long PIo4x[] = { _0x(0fda,4049), _0x(68c2,a221)};
  56. static long PIo2x[] = { _0x(0fda,40c9), _0x(68c2,a221)};
  57. static long PI3o4x[] = { _0x(cbe3,4116), _0x(0e92,f999)};
  58. static long PIx[] = { _0x(0fda,4149), _0x(68c2,a221)};
  59. static long PI2x[] = { _0x(0fda,41c9), _0x(68c2,a221)};
  60. #define thresh (*(double*)threshx)
  61. #define PIo4 (*(double*)PIo4x)
  62. #define PIo2 (*(double*)PIo2x)
  63. #define PI3o4 (*(double*)PI3o4x)
  64. #define PI (*(double*)PIx)
  65. #define PI2 (*(double*)PI2x)
  66. #else /* defined(vax)||defined(tahoe) */
  67. static double
  68. thresh =  2.6117239648121182150E-1    , /*Hex  2^ -2   *  1.0B70C6D604DD4 */
  69. PIo4 =  7.8539816339744827900E-1    , /*Hex  2^ -1   *  1.921FB54442D18 */
  70. PIo2 =  1.5707963267948965580E0     , /*Hex  2^  0   *  1.921FB54442D18 */
  71. PI3o4 =  2.3561944901923448370E0     , /*Hex  2^  1   *  1.2D97C7F3321D2 */
  72. PI =  3.1415926535897931160E0     , /*Hex  2^  1   *  1.921FB54442D18 */
  73. PI2 =  6.2831853071795862320E0     ; /*Hex  2^  2   *  1.921FB54442D18 */
  74. #ifdef national
  75. static long fmaxx[] = { 0xffffffff, 0x7fefffff};
  76. #define   fmax    (*(double*)fmaxx)
  77. #endif /* national */
  78. #endif /* defined(vax)||defined(tahoe) */
  79. static double
  80. zero = 0,
  81. one = 1,
  82. negone = -1,
  83. half = 1.0/2.0,
  84. small = 1E-10, /* 1+small**2 == 1; better values for small:
  85.  * small = 1.5E-9 for VAX D
  86.  * = 1.2E-8 for IEEE Double
  87.  * = 2.8E-10 for IEEE Extended
  88.  */
  89. big = 1E20; /* big := 1/(small**2) */
  90. /* sin__S(x*x) ... re-implemented as a macro
  91.  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
  92.  * STATIC KERNEL FUNCTION OF SIN(X), COS(X), AND TAN(X)
  93.  * CODED IN C BY K.C. NG, 1/21/85;
  94.  * REVISED BY K.C. NG on 8/13/85.
  95.  *
  96.  *     sin(x*k) - x
  97.  * RETURN  --------------- on [-PI/4,PI/4] , where k=pi/PI, PI is the rounded
  98.  *             x
  99.  * value of pi in machine precision:
  100.  *
  101.  * Decimal:
  102.  * pi = 3.141592653589793 23846264338327 .....
  103.  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
  104.  *    56 bits   PI = 3.141592653589793 227020265 ..... ,
  105.  *
  106.  * Hexadecimal:
  107.  * pi = 3.243F6A8885A308D313198A2E....
  108.  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18
  109.  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2
  110.  *
  111.  * Method:
  112.  * 1. Let z=x*x. Create a polynomial approximation to
  113.  *     (sin(k*x)-x)/x  =  z*(S0 + S1*z^1 + ... + S5*z^5).
  114.  * Then
  115.  *      sin__S(x*x) = z*(S0 + S1*z^1 + ... + S5*z^5)
  116.  *
  117.  * The coefficient S's are obtained by a special Remez algorithm.
  118.  *
  119.  * Accuracy:
  120.  * In the absence of rounding error, the approximation has absolute error
  121.  * less than 2**(-61.11) for VAX D FORMAT, 2**(-57.45) for IEEE DOUBLE.
  122.  *
  123.  * Constants:
  124.  * The hexadecimal values are the intended ones for the following constants.
  125.  * The decimal values may be used, provided that the compiler will convert
  126.  * from decimal to binary accurately enough to produce the hexadecimal values
  127.  * shown.
  128.  *
  129.  */
  130. #if defined(vax)||defined(tahoe)
  131. /*S0     = -1.6666666666666646660E-1    , Hex  2^ -2   * -.AAAAAAAAAAAA71 */
  132. /*S1     =  8.3333333333297230413E-3    , Hex  2^ -6   *  .8888888888477F */
  133. /*S2     = -1.9841269838362403710E-4    , Hex  2^-12   * -.D00D00CF8A1057 */
  134. /*S3     =  2.7557318019967078930E-6    , Hex  2^-18   *  .B8EF1CA326BEDC */
  135. /*S4     = -2.5051841873876551398E-8    , Hex  2^-25   * -.D73195374CE1D3 */
  136. /*S5     =  1.6028995389845827653E-10   , Hex  2^-32   *  .B03D9C6D26CCCC */
  137. /*S6     = -6.2723499671769283121E-13   ; Hex  2^-40   * -.B08D0B7561EA82 */
  138. static long S0x[] = { _0x(aaaa,bf2a), _0x(aa71,aaaa)};
  139. static long S1x[] = { _0x(8888,3d08), _0x(477f,8888)};
  140. static long S2x[] = { _0x(0d00,ba50), _0x(1057,cf8a)};
  141. static long S3x[] = { _0x(ef1c,3738), _0x(bedc,a326)};
  142. static long S4x[] = { _0x(3195,b3d7), _0x(e1d3,374c)};
  143. static long S5x[] = { _0x(3d9c,3030), _0x(cccc,6d26)};
  144. static long S6x[] = { _0x(8d0b,ac30), _0x(ea82,7561)};
  145. #define S0 (*(double*)S0x)
  146. #define S1 (*(double*)S1x)
  147. #define S2 (*(double*)S2x)
  148. #define S3 (*(double*)S3x)
  149. #define S4 (*(double*)S4x)
  150. #define S5 (*(double*)S5x)
  151. #define S6 (*(double*)S6x)
  152. #else /* IEEE double */
  153. static double
  154. S0     = -1.6666666666666463126E-1    , /*Hex  2^ -3   * -1.555555555550C */
  155. S1     =  8.3333333332992771264E-3    , /*Hex  2^ -7   *  1.111111110C461 */
  156. S2     = -1.9841269816180999116E-4    , /*Hex  2^-13   * -1.A01A019746345 */
  157. S3     =  2.7557309793219876880E-6    , /*Hex  2^-19   *  1.71DE3209CDCD9 */
  158. S4     = -2.5050225177523807003E-8    , /*Hex  2^-26   * -1.AE5C0E319A4EF */
  159. S5     =  1.5868926979889205164E-10   ; /*Hex  2^-33   *  1.5CF61DF672B13 */
  160. #endif
  161. #if defined(vax)||defined(tahoe)
  162. #define sin__S(z) (z*(S0+z*(S1+z*(S2+z*(S3+z*(S4+z*(S5+z*S6)))))))
  163. #else /* defined(vax)||defined(tahoe) */
  164. #define sin__S(z) (z*(S0+z*(S1+z*(S2+z*(S3+z*(S4+z*S5))))))
  165. #endif /* defined(vax)||defined(tahoe) */
  166. /* cos__C(x*x) ... re-implemented as a macro
  167.  * DOUBLE PRECISION (VAX D FORMAT 56 BITS, IEEE DOUBLE 53 BITS)
  168.  * STATIC KERNEL FUNCTION OF SIN(X), COS(X), AND TAN(X)
  169.  * CODED IN C BY K.C. NG, 1/21/85;
  170.  * REVISED BY K.C. NG on 8/13/85.
  171.  *
  172.  *         x*x
  173.  * RETURN   cos(k*x) - 1 + ----- on [-PI/4,PI/4],  where k = pi/PI,
  174.  *         2
  175.  * PI is the rounded value of pi in machine precision :
  176.  *
  177.  * Decimal:
  178.  * pi = 3.141592653589793 23846264338327 .....
  179.  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
  180.  *    56 bits   PI = 3.141592653589793 227020265 ..... ,
  181.  *
  182.  * Hexadecimal:
  183.  * pi = 3.243F6A8885A308D313198A2E....
  184.  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18
  185.  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2
  186.  *
  187.  *
  188.  * Method:
  189.  * 1. Let z=x*x. Create a polynomial approximation to
  190.  *     cos(k*x)-1+z/2  =  z*z*(C0 + C1*z^1 + ... + C5*z^5)
  191.  * then
  192.  *      cos__C(z) =  z*z*(C0 + C1*z^1 + ... + C5*z^5)
  193.  *
  194.  * The coefficient C's are obtained by a special Remez algorithm.
  195.  *
  196.  * Accuracy:
  197.  * In the absence of rounding error, the approximation has absolute error
  198.  * less than 2**(-64) for VAX D FORMAT, 2**(-58.3) for IEEE DOUBLE.
  199.  *
  200.  *
  201.  * Constants:
  202.  * The hexadecimal values are the intended ones for the following constants.
  203.  * The decimal values may be used, provided that the compiler will convert
  204.  * from decimal to binary accurately enough to produce the hexadecimal values
  205.  * shown.
  206.  *
  207.  */
  208. #if defined(vax)||defined(tahoe)
  209. /*C0     =  4.1666666666666504759E-2    , Hex  2^ -4   *  .AAAAAAAAAAA9F0 */
  210. /*C1     = -1.3888888888865302059E-3    , Hex  2^ -9   * -.B60B60B60A0CCA */
  211. /*C2     =  2.4801587285601038265E-5    , Hex  2^-15   *  .D00D00CDCD098F */
  212. /*C3     = -2.7557313470902390219E-7    , Hex  2^-21   * -.93F27BB593E805 */
  213. /*C4     =  2.0875623401082232009E-9    , Hex  2^-28   *  .8F74C8FA1E3FF0 */
  214. /*C5     = -1.1355178117642986178E-11   ; Hex  2^-36   * -.C7C32D0A5C5A63 */
  215. static long C0x[] = { _0x(aaaa,3e2a), _0x(a9f0,aaaa)};
  216. static long C1x[] = { _0x(0b60,bbb6), _0x(0cca,b60a)};
  217. static long C2x[] = { _0x(0d00,38d0), _0x(098f,cdcd)};
  218. static long C3x[] = { _0x(f27b,b593), _0x(e805,b593)};
  219. static long C4x[] = { _0x(74c8,320f), _0x(3ff0,fa1e)};
  220. static long C5x[] = { _0x(c32d,ae47), _0x(5a63,0a5c)};
  221. #define C0 (*(double*)C0x)
  222. #define C1 (*(double*)C1x)
  223. #define C2 (*(double*)C2x)
  224. #define C3 (*(double*)C3x)
  225. #define C4 (*(double*)C4x)
  226. #define C5 (*(double*)C5x)
  227. #else /* defined(vax)||defined(tahoe) */
  228. static double
  229. C0     =  4.1666666666666504759E-2    , /*Hex  2^ -5   *  1.555555555553E */
  230. C1     = -1.3888888888865301516E-3    , /*Hex  2^-10   * -1.6C16C16C14199 */
  231. C2     =  2.4801587269650015769E-5    , /*Hex  2^-16   *  1.A01A01971CAEB */
  232. C3     = -2.7557304623183959811E-7    , /*Hex  2^-22   * -1.27E4F1314AD1A */
  233. C4     =  2.0873958177697780076E-9    , /*Hex  2^-29   *  1.1EE3B60DDDC8C */
  234. C5     = -1.1250289076471311557E-11   ; /*Hex  2^-37   * -1.8BD5986B2A52E */
  235. #endif /* defined(vax)||defined(tahoe) */
  236. #define cos__C(z) (z*z*(C0+z*(C1+z*(C2+z*(C3+z*(C4+z*C5))))))
  237. /* function declarations */
  238. #if defined(__STDC__) || defined(__cplusplus)
  239. extern int finite(double x);
  240. extern double copysign(double x, double y);
  241. extern double drem(double x, double p);
  242. #else /* __STDC__ */
  243. extern int finite();
  244. extern double copysign();
  245. extern double drem();
  246. #endif /* __STDC__ */
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. #endif /* __INCtrigPh */