trigd_lib.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* Stub for defining degree-valued trigonometric functions in libgfortran.
  2. Copyright (C) 2020-2022 Free Software Foundation, Inc.
  3. Contributed by Steven G. Kargl <kargl@gcc.gnu.org>
  4. and Fritz Reese <foreese@gcc.gnu.org>
  5. This file is part of the GNU Fortran runtime library (libgfortran).
  6. Libgfortran is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public
  8. License as published by the Free Software Foundation; either
  9. version 3 of the License, or (at your option) any later version.
  10. Libgfortran is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. /*
  22. This replaces all GMP/MPFR functions used by trigd.inc with native versions.
  23. The precision is defined by FTYPE defined before including this file.
  24. The module which includes this file must define the following:
  25. KIND -- floating point kind (4, 8, 10, 16)
  26. HAVE_INFINITY_KIND -- defined iff the platform has GFC_REAL_<KIND>_INFINITY
  27. TINY [optional] -- subtract from 1 under the above condition if set
  28. COSD_SMALL [optional] -- for x <= COSD_SMALL, COSD(x) = 1 if set
  29. SIND_SMALL [optional] -- for x <= SIND_SMALL, SIND(x) = D2R(x) if set
  30. COSD30 -- literal value of COSD(30) to the precision of FTYPE
  31. PIO180H -- upper bits of pi/180 for FMA
  32. PIO180L -- lower bits of pi/180 for FMA
  33. */
  34. /* FTYPE := GFC_REAL_<K> */
  35. #define FTYPE CONCAT_EXPAND(GFC_REAL_,KIND)
  36. /* LITERAL_SUFFIX := GFC_REAL_<K>_LITERAL_SUFFIX */
  37. #define LITERAL_SUFFIX CONCAT_EXPAND(FTYPE,_LITERAL_SUFFIX)
  38. /* LITERAL(X) := GFC_REAL_<K>_LITERAL(X) */
  39. #define LITERAL(x) CONCAT_EXPAND(x,LITERAL_SUFFIX)
  40. #define SIND CONCAT_EXPAND(sind_r, KIND)
  41. #define COSD CONCAT_EXPAND(cosd_r, KIND)
  42. #define TAND CONCAT_EXPAND(tand_r, KIND)
  43. #ifdef HAVE_INFINITY_KIND
  44. /* GFC_REAL_X_INFINITY */
  45. #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _INFINITY)
  46. #else
  47. /* GFC_REAL_X_HUGE */
  48. #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _HUGE)
  49. #endif
  50. #define CONCAT(x,y) x ## y
  51. #define CONCAT_EXPAND(x,y) CONCAT(x,y)
  52. #ifndef COPYSIGN
  53. #define COPYSIGN LITERAL(copysign)
  54. #define FMOD LITERAL(fmod)
  55. #define FABS LITERAL(fabs)
  56. #define FMA LITERAL(fma)
  57. #define SIN LITERAL(sin)
  58. #define COS LITERAL(cos)
  59. #define TAN LITERAL(tan)
  60. #endif
  61. #ifdef TINY
  62. #define TINY_LITERAL LITERAL(TINY)
  63. #endif
  64. #ifdef COSD_SMALL
  65. #define COSD_SMALL_LITERAL LITERAL(COSD_SMALL)
  66. #endif
  67. #ifdef SIND_SMALL
  68. #define SIND_SMALL_LITERAL LITERAL(SIND_SMALL)
  69. #endif
  70. #define COSD30_LITERAL LITERAL(COSD30)
  71. #define PIO180H_LITERAL LITERAL(PIO180H)
  72. #define PIO180L_LITERAL LITERAL(PIO180L)
  73. #define ITYPE int
  74. #define GFC_RND_MODE 0
  75. #define RETTYPE FTYPE
  76. #define RETURN(x) return (x)
  77. #define ISFINITE(x) isfinite(x)
  78. #define mpfr_init(x) do { } while (0)
  79. #define mpfr_init_set_ui(x, v, rnd) (x = (v))
  80. #define mpfr_clear(x) do { } while (0)
  81. #define mpfr_swap(x, y) do { FTYPE z = y; y = x; x = z; } while (0)
  82. #define mpfr_copysign(rop, op1, op2, rnd) rop = COPYSIGN((op1), (op2))
  83. #define mpfr_fmod(rop, x, d, rnd) (rop = FMOD((x), (d)))
  84. #define mpfr_abs(rop, op, rnd) (rop = FABS(op))
  85. #define mpfr_cmp_ld(x, y) ((x) - (y))
  86. #define mpfr_cmp_ui(x, n) ((x) - (n))
  87. #define mpfr_zero_p(x) ((x) == 0)
  88. #define mpfr_set(rop, x, rnd) (rop = (x))
  89. #define mpfr_set_zero(rop, s) (rop = COPYSIGN(0, (s)))
  90. #define mpfr_set_inf(rop, s) (rop = ((s)*-2 + 1) * INFINITY_KIND)
  91. #define mpfr_set_ui(rop, n, rnd) (rop = (n))
  92. #define mpfr_set_si(rop, n, rnd) (rop = (n))
  93. #define mpfr_set_ld(rop, x, rnd) (rop = (x))
  94. #define mpfr_set_si_2exp(rop, op, exp, rnd) (rop = (0x1.p##exp))
  95. #define mpfr_get_z(rop, x, rnd) ((rop = (int)(x)), (rop - (x)))
  96. #define mpfr_mul(rop, op1, op2, rnd) (rop = ((op1) * (op2)))
  97. #define mpfr_sub_d(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
  98. #define mpfr_sub_ui(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
  99. #define mpfr_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
  100. #define mpfr_ui_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
  101. #define mpfr_neg(rop, op, rnd) (rop = -(op))
  102. #define mpfr_sin(rop, x, rnd) (rop = SIN(x))
  103. #define mpfr_cos(rop, x, rnd) (rop = COS(x))
  104. #define mpfr_tan(rop, x, rnd) (rop = TAN(x))
  105. #define mpz_init(n) do { } while (0)
  106. #define mpz_clear(x) do { } while (0)
  107. #define mpz_cmp_ui(x, y) ((x) - (y))
  108. #define mpz_divisible_ui_p(n, d) ((n) % (d) == 0)
  109. #define D2R(x) (x = FMA((x), PIO180H_LITERAL, (x) * PIO180L_LITERAL))
  110. #define SET_COSD30(x) (x = COSD30_LITERAL)
  111. #ifdef SIND
  112. extern FTYPE SIND (FTYPE);
  113. export_proto (SIND);
  114. #endif
  115. #ifdef COSD
  116. extern FTYPE COSD (FTYPE);
  117. export_proto (COSD);
  118. #endif
  119. #ifdef TAND
  120. extern FTYPE TAND (FTYPE);
  121. export_proto (TAND);
  122. #endif
  123. #include "trigd.inc"
  124. #undef FTYPE
  125. #undef LITERAL_SUFFIX
  126. #undef LITERAL
  127. #undef CONCAT3
  128. #undef CONCAT3_EXPAND
  129. #undef CONCAT
  130. #undef CONCAT_EXPAND
  131. #undef SIND
  132. #undef COSD
  133. #undef TAND
  134. #undef INFINITY_KIND
  135. #undef COPYSIGN
  136. #undef FMOD
  137. #undef FABS
  138. #undef FMA
  139. #undef SIN
  140. #undef COS
  141. #undef TAN
  142. #undef TINY_LITERAL
  143. #undef COSD_SMALL_LITERAL
  144. #undef SIND_SMALL_LITERAL
  145. #undef COSD30_LITERAL
  146. #undef PIO180H_LITERAL
  147. #undef PIO180L_LITERAL
  148. #undef ITYPE
  149. #undef GFC_RND_MODE
  150. #undef RETTYPE
  151. #undef RETURN
  152. #undef ISFINITE
  153. #undef mpfr_signbit
  154. #undef mpfr_init
  155. #undef mpfr_init_set_ui
  156. #undef mpfr_clear
  157. #undef mpfr_swap
  158. #undef mpfr_fmod
  159. #undef mpfr_abs
  160. #undef mpfr_cmp_ld
  161. #undef mpfr_cmp_ui
  162. #undef mpfr_zero_p
  163. #undef mpfr_set
  164. #undef mpfr_set_zero
  165. #undef mpfr_set_inf
  166. #undef mpfr_set_ui
  167. #undef mpfr_set_si
  168. #undef mpfr_set_ld
  169. #undef mpfr_set_si_2exp
  170. #undef mpfr_get_z
  171. #undef mpfr_mul_si
  172. #undef mpfr_sub_d
  173. #undef mpfr_sub_ui
  174. #undef mpfr_sub
  175. #undef mpfr_ui_sub
  176. #undef mpfr_neg
  177. #undef mpfr_sin
  178. #undef mpfr_cos
  179. #undef mpfr_tan
  180. #undef mpz_init
  181. #undef mpz_clear
  182. #undef mpz_cmp_ui
  183. #undef mpz_divisible_ui_p
  184. #undef FMA
  185. #undef D2R
  186. #undef SET_COSD30
  187. /* vim: set ft=c: */