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>
6 This file is part of the GNU Fortran runtime library (libgfortran).
8 Libgfortran is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 3 of the License, or (at your option) any later version.
13 Libgfortran is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
28 This replaces all GMP/MPFR functions used by trigd.inc with native versions.
29 The precision is defined by FTYPE defined before including this file.
30 The module which includes this file must define the following:
32 KIND -- floating point kind (4, 8, 10, 16)
33 HAVE_INFINITY_KIND -- defined iff the platform has GFC_REAL_<KIND>_INFINITY
35 TINY [optional] -- subtract from 1 under the above condition if set
36 COSD_SMALL [optional] -- for x <= COSD_SMALL, COSD(x) = 1 if set
37 SIND_SMALL [optional] -- for x <= SIND_SMALL, SIND(x) = D2R(x) if set
38 COSD30 -- literal value of COSD(30) to the precision of FTYPE
39 PIO180H -- upper bits of pi/180 for FMA
40 PIO180L -- lower bits of pi/180 for FMA
44 /* FTYPE := GFC_REAL_<K> */
45 #define FTYPE CONCAT_EXPAND(GFC_REAL_,KIND)
47 /* LITERAL_SUFFIX := GFC_REAL_<K>_LITERAL_SUFFIX */
48 #define LITERAL_SUFFIX CONCAT_EXPAND(FTYPE,_LITERAL_SUFFIX)
50 /* LITERAL(X) := GFC_REAL_<K>_LITERAL(X) */
51 #define LITERAL(x) CONCAT_EXPAND(x,LITERAL_SUFFIX)
53 #define SIND CONCAT_EXPAND(sind_r, KIND)
54 #define COSD CONCAT_EXPAND(cosd_r, KIND)
55 #define TAND CONCAT_EXPAND(tand_r, KIND)
57 #ifdef HAVE_INFINITY_KIND
58 /* GFC_REAL_X_INFINITY */
59 #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _INFINITY)
62 #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _HUGE)
65 #define CONCAT(x,y) x ## y
66 #define CONCAT_EXPAND(x,y) CONCAT(x,y)
68 #define COPYSIGN LITERAL(copysign)
69 #define FMOD LITERAL(fmod)
70 #define FABS LITERAL(fabs)
71 #define FMA LITERAL(fma)
72 #define SIN LITERAL(sin)
73 #define COS LITERAL(cos)
74 #define TAN LITERAL(tan)
77 #define TINY_LITERAL LITERAL(TINY)
81 #define COSD_SMALL_LITERAL LITERAL(COSD_SMALL)
85 #define SIND_SMALL_LITERAL LITERAL(SIND_SMALL)
88 #define COSD30_LITERAL LITERAL(COSD30)
89 #define PIO180H_LITERAL LITERAL(PIO180H)
90 #define PIO180L_LITERAL LITERAL(PIO180L)
93 #define GFC_RND_MODE 0
95 #define RETURN(x) return (x)
97 #define ISFINITE(x) isfinite(x)
98 #define mpfr_init(x) do { } while (0)
99 #define mpfr_init_set_ui(x, v, rnd) (x = (v))
100 #define mpfr_clear(x) do { } while (0)
101 #define mpfr_swap(x, y) do { FTYPE z = y; y = x; x = z; } while (0)
102 #define mpfr_copysign(rop, op1, op2, rnd) rop = COPYSIGN((op1), (op2))
103 #define mpfr_fmod(rop, x, d, rnd) (rop = FMOD((x), (d)))
104 #define mpfr_abs(rop, op, rnd) (rop = FABS(op))
105 #define mpfr_cmp_ld(x, y) ((x) - (y))
106 #define mpfr_cmp_ui(x, n) ((x) - (n))
107 #define mpfr_zero_p(x) ((x) == 0)
108 #define mpfr_set(rop, x, rnd) (rop = (x))
109 #define mpfr_set_zero(rop, s) (rop = COPYSIGN(0, (s)))
110 #define mpfr_set_inf(rop, s) (rop = ((s)*-2 + 1) * INFINITY_KIND)
111 #define mpfr_set_ui(rop, n, rnd) (rop = (n))
112 #define mpfr_set_si(rop, n, rnd) (rop = (n))
113 #define mpfr_set_ld(rop, x, rnd) (rop = (x))
114 #define mpfr_set_si_2exp(rop, op, exp, rnd) (rop = (0x1.p##exp))
115 #define mpfr_get_z(rop, x, rnd) ((rop = (int)(x)), (rop - (x)))
116 #define mpfr_mul(rop, op1, op2, rnd) (rop = ((op1) * (op2)))
117 #define mpfr_sub_d(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
118 #define mpfr_sub_ui(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
119 #define mpfr_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
120 #define mpfr_ui_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
121 #define mpfr_neg(rop, op, rnd) (rop = -(op))
122 #define mpfr_sin(rop, x, rnd) (rop = SIN(x))
123 #define mpfr_cos(rop, x, rnd) (rop = COS(x))
124 #define mpfr_tan(rop, x, rnd) (rop = TAN(x))
126 #define mpz_init(n) do { } while (0)
127 #define mpz_clear(x) do { } while (0)
128 #define mpz_cmp_ui(x, y) ((x) - (y))
129 #define mpz_divisible_ui_p(n, d) ((n) % (d) == 0)
131 #define D2R(x) (x = FMA((x), PIO180H_LITERAL, (x) * PIO180L_LITERAL))
133 #define SET_COSD30(x) (x = COSD30_LITERAL)
136 extern FTYPE SIND (FTYPE);
141 extern FTYPE COSD (FTYPE);
146 extern FTYPE TAND (FTYPE);
153 #undef LITERAL_SUFFIX
156 #undef CONCAT3_EXPAND
173 #undef COSD_SMALL_LITERAL
174 #undef SIND_SMALL_LITERAL
175 #undef COSD30_LITERAL
176 #undef PIO180H_LITERAL
177 #undef PIO180L_LITERAL
188 #undef mpfr_init_set_ui
202 #undef mpfr_set_si_2exp
217 #undef mpz_divisible_ui_p