invtrig.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*-
  2. * Copyright (c) 2008 David Schultz <[email protected]>
  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. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. * $FreeBSD: src/lib/msun/ld80/invtrig.h,v 1.2 2008/08/02 03:56:22 das Exp $
  27. */
  28. #include <float.h>
  29. #include <openlibm_math.h>
  30. #define BIAS (LDBL_MAX_EXP - 1)
  31. #define MANH_SIZE LDBL_MANH_SIZE
  32. /* Approximation thresholds. */
  33. #define ASIN_LINEAR (BIAS - 32) /* 2**-32 */
  34. #define ACOS_CONST (BIAS - 65) /* 2**-65 */
  35. #define ATAN_CONST (BIAS + 65) /* 2**65 */
  36. #define ATAN_LINEAR (BIAS - 32) /* 2**-32 */
  37. /* 0.95 */
  38. #define THRESH ((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT)
  39. /* Constants shared by the long double inverse trig functions. */
  40. #define pS0 _ItL_pS0
  41. #define pS1 _ItL_pS1
  42. #define pS2 _ItL_pS2
  43. #define pS3 _ItL_pS3
  44. #define pS4 _ItL_pS4
  45. #define pS5 _ItL_pS5
  46. #define pS6 _ItL_pS6
  47. #define qS1 _ItL_qS1
  48. #define qS2 _ItL_qS2
  49. #define qS3 _ItL_qS3
  50. #define qS4 _ItL_qS4
  51. #define qS5 _ItL_qS5
  52. #define atanhi _ItL_atanhi
  53. #define atanlo _ItL_atanlo
  54. #define aT _ItL_aT
  55. #define pi_lo _ItL_pi_lo
  56. #define pio2_hi atanhi[3]
  57. #define pio2_lo atanlo[3]
  58. #define pio4_hi atanhi[1]
  59. #ifdef STRUCT_DECLS
  60. typedef struct longdouble {
  61. uint64_t mant;
  62. uint16_t expsign;
  63. } LONGDOUBLE;
  64. #else
  65. typedef long double LONGDOUBLE;
  66. #endif
  67. extern const LONGDOUBLE pS0, pS1, pS2, pS3, pS4, pS5, pS6;
  68. extern const LONGDOUBLE qS1, qS2, qS3, qS4, qS5;
  69. extern const LONGDOUBLE atanhi[], atanlo[], aT[];
  70. extern const LONGDOUBLE pi_lo;
  71. #ifndef STRUCT_DECLS
  72. static inline long double
  73. P(long double x)
  74. {
  75. return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \
  76. (pS4 + x * (pS5 + x * pS6)))))));
  77. }
  78. static inline long double
  79. Q(long double x)
  80. {
  81. return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * qS5)))));
  82. }
  83. static inline long double
  84. T_even(long double x)
  85. {
  86. return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \
  87. (aT[8] + x * (aT[10] + x * aT[12]))))));
  88. }
  89. static inline long double
  90. T_odd(long double x)
  91. {
  92. return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \
  93. (aT[9] + x * aT[11])))));
  94. }
  95. #endif