b6d4145b99527fbb422ae0e5f48c37368ef61fb2
[platform/upstream/gcc.git] / libgfortran / intrinsics / trigd_lib.inc
1 /* Stub for defining degree-valued trigonometric functions in libgfortran.
2    Copyright (C) 2020 Free Software Foundation, Inc.
3    Contributed by Steven G. Kargl <kargl@gcc.gnu.org>
4    and Fritz Reese <foreese@gcc.gnu.org>
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 FTYPE             -- floating point type
33 SIND, COSD, TAND  -- names of the functions to define
34 SUFFIX(x)         -- add a literal suffix for floating point constants (f, ...)
35
36 COSD_SMALL [optional] -- for x <= COSD_SMALL, COSD(x) = 1 if set
37 TINY       [optional] -- subtract from 1 under the above condition if set
38 SIND_SMALL [optional] -- for x <= SIND_SMALL, SIND(x) = D2R(x) if set
39 COSD30                -- literal value of COSD(30) to the precision of FTYPE
40 PIO180H               -- upper bits of pi/180 for FMA
41 PIO180L               -- lower bits of pi/180 for FMA
42
43  */
44
45 #define ITYPE int
46 #define GFC_RND_MODE 0
47 #define RETTYPE FTYPE
48 #define RETURN(x) return (x)
49
50 #define ISFINITE(x) isfinite(x)
51 #define mpfr_init(x) do { } while (0)
52 #define mpfr_init_set_ui(x, v, rnd) (x = (v))
53 #define mpfr_clear(x) do { } while (0)
54 #define mpfr_swap(x, y) do { FTYPE z = y; y = x; x = z; } while (0)
55 #define mpfr_copysign(rop, op1, op2, rnd) rop = SUFFIX(copysign)((op1), (op2))
56 #define mpfr_fmod(rop, x, d, rnd) (rop = SUFFIX(fmod)((x), (d)))
57 #define mpfr_abs(rop, op, rnd) (rop = SUFFIX(fabs)(op))
58 #define mpfr_cmp_ld(x, y) ((x) - (y))
59 #define mpfr_cmp_ui(x, n) ((x) - (n))
60 #define mpfr_zero_p(x) ((x) == 0)
61 #define mpfr_set(rop, x, rnd) (rop = (x))
62 #define mpfr_set_zero(rop, s) (rop = SUFFIX(copysign)(0, (s)))
63 #define mpfr_set_inf(rop, s) (rop = ((s)*-2 + 1) * INFINITY)
64 #define mpfr_set_ui(rop, n, rnd) (rop = (n))
65 #define mpfr_set_si(rop, n, rnd) (rop = (n))
66 #define mpfr_set_ld(rop, x, rnd) (rop = (x))
67 #define mpfr_set_si_2exp(rop, op, exp, rnd) (rop = (0x1.p##exp))
68 #define mpfr_get_z(rop, x, rnd) ((rop = (int)(x)), (rop - (x)))
69 #define mpfr_mul(rop, op1, op2, rnd)    (rop = ((op1) * (op2)))
70 #define mpfr_sub_d(rop, op1, op2, rnd)  (rop = ((op1) - (op2)))
71 #define mpfr_sub_ui(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
72 #define mpfr_sub(rop, op1, op2, rnd)    (rop = ((op1) - (op2)))
73 #define mpfr_ui_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
74 #define mpfr_neg(rop, op, rnd) (rop = -(op))
75 #define mpfr_sin(rop, x, rnd) (rop = SUFFIX(sin)(x))
76 #define mpfr_cos(rop, x, rnd) (rop = SUFFIX(cos)(x))
77 #define mpfr_tan(rop, x, rnd) (rop = SUFFIX(tan)(x))
78
79 #define mpz_init(n) do { } while (0)
80 #define mpz_clear(x) do { } while (0)
81 #define mpz_cmp_ui(x, y) ((x) - (y))
82 #define mpz_divisible_ui_p(n, d) ((n) % (d) == 0)
83
84 #define FMA(x,y,z)  SUFFIX(fma)((x), (y), (z))
85 #define D2R(x) (x = FMA((x), PIO180H, (x) * PIO180L))
86
87 #define SET_COSD30(x) (x = COSD30)
88
89
90 extern FTYPE SIND (FTYPE);
91 export_proto (SIND);
92
93 extern FTYPE COSD (FTYPE);
94 export_proto (COSD);
95
96 extern FTYPE TAND (FTYPE);
97 export_proto (TAND);
98
99 #include "trigd.inc"
100
101 #undef ITYPE
102 #undef GFC_RND_MODE
103 #undef RETTYPE
104 #undef RETURN
105
106 #undef ISFINITE
107 #undef mpfr_signbit
108
109 #undef mpfr_init
110 #undef mpfr_init_set_ui
111 #undef mpfr_clear
112 #undef mpfr_swap
113 #undef mpfr_fmod
114 #undef mpfr_abs
115 #undef mpfr_cmp_ld
116 #undef mpfr_cmp_ui
117 #undef mpfr_zero_p
118 #undef mpfr_set
119 #undef mpfr_set_zero
120 #undef mpfr_set_inf
121 #undef mpfr_set_ui
122 #undef mpfr_set_si
123 #undef mpfr_set_ld
124 #undef mpfr_set_si_2exp
125 #undef mpfr_get_z
126 #undef mpfr_mul_si
127 #undef mpfr_sub_d
128 #undef mpfr_sub_ui
129 #undef mpfr_sub
130 #undef mpfr_ui_sub
131 #undef mpfr_neg
132 #undef mpfr_sin
133 #undef mpfr_cos
134 #undef mpfr_tan
135
136 #undef mpz_init
137 #undef mpz_clear
138 #undef mpz_cmp_ui
139 #undef mpz_divisible_ui_p
140
141 #undef FMA
142 #undef D2R
143
144 #undef SET_COSD30
145
146
147 /* vim: set ft=c: */