__invtrigl.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* origin: FreeBSD /usr/src/lib/msun/src/ld80/invtrig.h */
  2. /*-
  3. * Copyright (c) 2008 David Schultz <[email protected]>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #include "libm.h"
  28. #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  29. #define BIAS (LDBL_MAX_EXP - 1)
  30. #define MANH_SIZE LDBL_MANH_SIZE
  31. /* Approximation thresholds. */
  32. #define ASIN_LINEAR (BIAS - 32) /* 2**-32 */
  33. #define ACOS_CONST (BIAS - 65) /* 2**-65 */
  34. #define ATAN_CONST (BIAS + 65) /* 2**65 */
  35. #define ATAN_LINEAR (BIAS - 32) /* 2**-32 */
  36. /* 0.95 */
  37. #define THRESH ((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT)
  38. /* Constants shared by the long double inverse trig functions. */
  39. #define pS0 __pS0
  40. #define pS1 __pS1
  41. #define pS2 __pS2
  42. #define pS3 __pS3
  43. #define pS4 __pS4
  44. #define pS5 __pS5
  45. #define pS6 __pS6
  46. #define qS1 __qS1
  47. #define qS2 __qS2
  48. #define qS3 __qS3
  49. #define qS4 __qS4
  50. #define qS5 __qS5
  51. #define atanhi __atanhi
  52. #define atanlo __atanlo
  53. #define aT __aT
  54. #define pi_lo __pi_lo
  55. #define pio2_hi atanhi[3]
  56. #define pio2_lo atanlo[3]
  57. #define pio4_hi atanhi[1]
  58. #ifdef STRUCT_DECLS
  59. typedef struct longdouble {
  60. uint64_t mant;
  61. uint16_t expsign;
  62. } LONGDOUBLE;
  63. #else
  64. typedef long double LONGDOUBLE;
  65. #endif
  66. extern const LONGDOUBLE pS0, pS1, pS2, pS3, pS4, pS5, pS6;
  67. extern const LONGDOUBLE qS1, qS2, qS3, qS4, qS5;
  68. extern const LONGDOUBLE atanhi[], atanlo[], aT[];
  69. extern const LONGDOUBLE pi_lo;
  70. #ifndef STRUCT_DECLS
  71. static inline long double
  72. P(long double x)
  73. {
  74. return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
  75. (pS4 + x * (pS5 + x * pS6)))))));
  76. }
  77. static inline long double
  78. Q(long double x)
  79. {
  80. return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * qS5)))));
  81. }
  82. static inline long double
  83. T_even(long double x)
  84. {
  85. return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
  86. (aT[8] + x * (aT[10] + x * aT[12]))))));
  87. }
  88. static inline long double
  89. T_odd(long double x)
  90. {
  91. return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
  92. (aT[9] + x * aT[11])))));
  93. }
  94. #endif
  95. #endif