| 1 |
/* Stub for defining degree-valued trigonometric functions in libgfortran. |
| 2 |
Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Steven G. Kargl <[email protected]> |
| 4 |
and Fritz Reese <[email protected]> |
| 5 |
|
| 6 |
This file is part of the GNU Fortran runtime library (libgfortran). |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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. |
| 21 |
|
| 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/>. */ |
| 26 |
|
| 27 |
/* |
| 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: |
| 31 |
|
| 32 |
KIND -- floating point kind (4, 8, 10, 16) |
| 33 |
HAVE_INFINITY_KIND -- defined iff the platform has GFC_REAL_<KIND>_INFINITY |
| 34 |
|
| 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 |
| 41 |
|
| 42 |
*/ |
| 43 |
|
| 44 |
/* FTYPE := GFC_REAL_<K> */ |
| 45 |
#define FTYPE CONCAT_EXPAND(GFC_REAL_,KIND) |
| 46 |
|
| 47 |
/* LITERAL_SUFFIX := GFC_REAL_<K>_LITERAL_SUFFIX */ |
| 48 |
#define LITERAL_SUFFIX CONCAT_EXPAND(FTYPE,_LITERAL_SUFFIX) |
| 49 |
|
| 50 |
/* LITERAL(X) := GFC_REAL_<K>_LITERAL(X) */ |
| 51 |
#define LITERAL(x) CONCAT_EXPAND(x,LITERAL_SUFFIX) |
| 52 |
|
| 53 |
#define SIND CONCAT_EXPAND(sind_r, KIND) |
| 54 |
#define COSD CONCAT_EXPAND(cosd_r, KIND) |
| 55 |
#define TAND CONCAT_EXPAND(tand_r, KIND) |
| 56 |
|
| 57 |
#ifdef HAVE_INFINITY_KIND |
| 58 |
/* GFC_REAL_X_INFINITY */ |
| 59 |
#define INFINITY_KIND CONCAT_EXPAND(FTYPE, _INFINITY) |
| 60 |
#else |
| 61 |
/* GFC_REAL_X_HUGE */ |
| 62 |
#define INFINITY_KIND CONCAT_EXPAND(FTYPE, _HUGE) |
| 63 |
#endif |
| 64 |
|
| 65 |
#define CONCAT(x,y) x ## y |
| 66 |
#define CONCAT_EXPAND(x,y) CONCAT(x,y) |
| 67 |
|
| 68 |
#ifndef COPYSIGN |
| 69 |
#define COPYSIGN LITERAL(copysign) |
| 70 |
#define FMOD LITERAL(fmod) |
| 71 |
#define FABS LITERAL(fabs) |
| 72 |
#define FMA LITERAL(fma) |
| 73 |
#define SIN LITERAL(sin) |
| 74 |
#define COS LITERAL(cos) |
| 75 |
#define TAN LITERAL(tan) |
| 76 |
#endif |
| 77 |
|
| 78 |
#ifdef TINY |
| 79 |
#define TINY_LITERAL LITERAL(TINY) |
| 80 |
#endif |
| 81 |
|
| 82 |
#ifdef COSD_SMALL |
| 83 |
#define COSD_SMALL_LITERAL LITERAL(COSD_SMALL) |
| 84 |
#endif |
| 85 |
|
| 86 |
#ifdef SIND_SMALL |
| 87 |
#define SIND_SMALL_LITERAL LITERAL(SIND_SMALL) |
| 88 |
#endif |
| 89 |
|
| 90 |
#define COSD30_LITERAL LITERAL(COSD30) |
| 91 |
#define PIO180H_LITERAL LITERAL(PIO180H) |
| 92 |
#define PIO180L_LITERAL LITERAL(PIO180L) |
| 93 |
|
| 94 |
#define ITYPE int |
| 95 |
#define GFC_RND_MODE 0 |
| 96 |
#define RETTYPE FTYPE |
| 97 |
#define RETURN(x) return (x) |
| 98 |
|
| 99 |
#define ISFINITE(x) isfinite(x) |
| 100 |
#define mpfr_init(x) do { } while (0) |
| 101 |
#define mpfr_init_set_ui(x, v, rnd) (x = (v)) |
| 102 |
#define mpfr_clear(x) do { } while (0) |
| 103 |
#define mpfr_swap(x, y) do { FTYPE z = y; y = x; x = z; } while (0) |
| 104 |
#define mpfr_copysign(rop, op1, op2, rnd) rop = COPYSIGN((op1), (op2)) |
| 105 |
#define mpfr_fmod(rop, x, d, rnd) (rop = FMOD((x), (d))) |
| 106 |
#define mpfr_abs(rop, op, rnd) (rop = FABS(op)) |
| 107 |
#define mpfr_cmp_ld(x, y) ((x) - (y)) |
| 108 |
#define mpfr_cmp_ui(x, n) ((x) - (n)) |
| 109 |
#define mpfr_zero_p(x) ((x) == 0) |
| 110 |
#define mpfr_set(rop, x, rnd) (rop = (x)) |
| 111 |
#define mpfr_set_zero(rop, s) (rop = COPYSIGN(0, (s))) |
| 112 |
#define mpfr_set_inf(rop, s) (rop = ((s)*-2 + 1) * INFINITY_KIND) |
| 113 |
#define mpfr_set_ui(rop, n, rnd) (rop = (n)) |
| 114 |
#define mpfr_set_si(rop, n, rnd) (rop = (n)) |
| 115 |
#define mpfr_set_ld(rop, x, rnd) (rop = (x)) |
| 116 |
#define mpfr_set_si_2exp(rop, op, exp, rnd) (rop = (0x1.p##exp)) |
| 117 |
#define mpfr_get_z(rop, x, rnd) ((rop = (int)(x)), (rop - (x))) |
| 118 |
#define mpfr_mul(rop, op1, op2, rnd) (rop = ((op1) * (op2))) |
| 119 |
#define mpfr_sub_d(rop, op1, op2, rnd) (rop = ((op1) - (op2))) |
| 120 |
#define mpfr_sub_ui(rop, op1, op2, rnd) (rop = ((op1) - (op2))) |
| 121 |
#define mpfr_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2))) |
| 122 |
#define mpfr_ui_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2))) |
| 123 |
#define mpfr_neg(rop, op, rnd) (rop = -(op)) |
| 124 |
#define mpfr_sin(rop, x, rnd) (rop = SIN(x)) |
| 125 |
#define mpfr_cos(rop, x, rnd) (rop = COS(x)) |
| 126 |
#define mpfr_tan(rop, x, rnd) (rop = TAN(x)) |
| 127 |
|
| 128 |
#define mpz_init(n) do { } while (0) |
| 129 |
#define mpz_clear(x) do { } while (0) |
| 130 |
#define mpz_cmp_ui(x, y) ((x) - (y)) |
| 131 |
#define mpz_divisible_ui_p(n, d) ((n) % (d) == 0) |
| 132 |
|
| 133 |
#define D2R(x) (x = FMA((x), PIO180H_LITERAL, (x) * PIO180L_LITERAL)) |
| 134 |
|
| 135 |
#define SET_COSD30(x) (x = COSD30_LITERAL) |
| 136 |
|
| 137 |
#ifdef SIND |
| 138 |
extern FTYPE SIND (FTYPE); |
| 139 |
export_proto (SIND); |
| 140 |
#endif |
| 141 |
|
| 142 |
#ifdef COSD |
| 143 |
extern FTYPE COSD (FTYPE); |
| 144 |
export_proto (COSD); |
| 145 |
#endif |
| 146 |
|
| 147 |
#ifdef TAND |
| 148 |
extern FTYPE TAND (FTYPE); |
| 149 |
export_proto (TAND); |
| 150 |
#endif |
| 151 |
|
| 152 |
#include "trigd.inc" |
| 153 |
|
| 154 |
#undef FTYPE |
| 155 |
#undef LITERAL_SUFFIX |
| 156 |
#undef LITERAL |
| 157 |
#undef CONCAT3 |
| 158 |
#undef CONCAT3_EXPAND |
| 159 |
#undef CONCAT |
| 160 |
#undef CONCAT_EXPAND |
| 161 |
#undef SIND |
| 162 |
#undef COSD |
| 163 |
#undef TAND |
| 164 |
#undef INFINITY_KIND |
| 165 |
|
| 166 |
#undef COPYSIGN |
| 167 |
#undef FMOD |
| 168 |
#undef FABS |
| 169 |
#undef FMA |
| 170 |
#undef SIN |
| 171 |
#undef COS |
| 172 |
#undef TAN |
| 173 |
|
| 174 |
#undef TINY_LITERAL |
| 175 |
#undef COSD_SMALL_LITERAL |
| 176 |
#undef SIND_SMALL_LITERAL |
| 177 |
#undef COSD30_LITERAL |
| 178 |
#undef PIO180H_LITERAL |
| 179 |
#undef PIO180L_LITERAL |
| 180 |
|
| 181 |
#undef ITYPE |
| 182 |
#undef GFC_RND_MODE |
| 183 |
#undef RETTYPE |
| 184 |
#undef RETURN |
| 185 |
|
| 186 |
#undef ISFINITE |
| 187 |
#undef mpfr_signbit |
| 188 |
|
| 189 |
#undef mpfr_init |
| 190 |
#undef mpfr_init_set_ui |
| 191 |
#undef mpfr_clear |
| 192 |
#undef mpfr_swap |
| 193 |
#undef mpfr_fmod |
| 194 |
#undef mpfr_abs |
| 195 |
#undef mpfr_cmp_ld |
| 196 |
#undef mpfr_cmp_ui |
| 197 |
#undef mpfr_zero_p |
| 198 |
#undef mpfr_set |
| 199 |
#undef mpfr_set_zero |
| 200 |
#undef mpfr_set_inf |
| 201 |
#undef mpfr_set_ui |
| 202 |
#undef mpfr_set_si |
| 203 |
#undef mpfr_set_ld |
| 204 |
#undef mpfr_set_si_2exp |
| 205 |
#undef mpfr_get_z |
| 206 |
#undef mpfr_mul_si |
| 207 |
#undef mpfr_sub_d |
| 208 |
#undef mpfr_sub_ui |
| 209 |
#undef mpfr_sub |
| 210 |
#undef mpfr_ui_sub |
| 211 |
#undef mpfr_neg |
| 212 |
#undef mpfr_sin |
| 213 |
#undef mpfr_cos |
| 214 |
#undef mpfr_tan |
| 215 |
|
| 216 |
#undef mpz_init |
| 217 |
#undef mpz_clear |
| 218 |
#undef mpz_cmp_ui |
| 219 |
#undef mpz_divisible_ui_p |
| 220 |
|
| 221 |
#undef FMA |
| 222 |
#undef D2R |
| 223 |
|
| 224 |
#undef SET_COSD30 |
| 225 |
|
| 226 |
|
| 227 |
/* vim: set ft=c: */ |