a68g-quad.h
1 //! @file a68g-double.h
2 //! @author J. Marcel van der Veer
3 //!
4 //! @section Copyright
5 //!
6 //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
7 //! Copyright 2001-2023 J. Marcel van der Veer [algol68g@xs4all.nl].
8 //!
9 //! @section License
10 //!
11 //! This program is free software; you can redistribute it and/or modify it
12 //! under the terms of the GNU General Public License as published by the
13 //! Free Software Foundation; either version 3 of the License, or
14 //! (at your option) any later version.
15 //!
16 //! This program is distributed in the hope that it will be useful, but
17 //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 //! more details. You should have received a copy of the GNU General Public
20 //! License along with this program. If not, see [http://www.gnu.org/licenses/].
21
22 #if !defined (__A68G_QUAD_H__)
23 #define __A68G_QUAD_H__
24
25 #if (A68_LEVEL >= 3)
26
27 #if defined (BUILD_WIN32)
28 #define __BYTE_ORDER __LITTLE_ENDIAN // WIN32 runs on Intel.
29 #else
30 #include <endian.h>
31 #endif
32
33 #define unt_2 uint16_t
34 #define FLT128_LEN 7 // Do NOT change this!
35 #define FLT256_LEN 15 // Do NOT change this!
36 #define HPA_VERSION "1.7 A68G"
37 #define FLT256_MANT_DIG (FLT256_LEN * 16)
38 #define QUAD_DIGITS MANT_DIGS (FLT256_MANT_DIG)
39
40 typedef unt_2 REAL16[8];
41 typedef unt_2 REAL32[FLT256_LEN + 1];
42 typedef struct QUAD_T QUAD_T;
43
44 struct QUAD_T
45 {
46 REAL32 value;
47 };
48
49 #define QV(z) (z.value)
50
51 #define FLT256_DIG 62
52 #define MAX_FLT256_DIG (FLT256_DIG + 6)
53 #define M_LOG10_2 0.30102999566398119521373889472449q
54
55 #define QUAD_RTE(where, err) abend ((char *) err, (char *) where, __FILE__, __LINE__)
56
57 #define _add_quad_real_(a, b) add_quad_real (a, b, 0)
58 #define _sub_quad_real_(a, b) add_quad_real (a, b, 1)
59
60 #define CHECK_QUAD_REAL(p, u) PRELUDE_ERROR (isMinf_quad_real (u) || isPinf_quad_real (u), p, ERROR_INFINITE, M_LONG_LONG_REAL)
61
62 #define CHECK_QUAD_COMPLEX(p, u, v)\
63 CHECK_QUAD_REAL (p, u);\
64 CHECK_QUAD_REAL (p, v);
65
66 // Shorthands to improve code legibility.
67
68 #define int_2 int16_t
69
70
71 #if defined (QUAD_REAL_ERR_IGN)
72 #define sigerr_quad_real(errcond, errcode, where) 0
73 #else
74 #define QUAD_REAL_EDIV 1
75 #define QUAD_REAL_EDOM 2
76 #define QUAD_REAL_EBADEXP 3
77 #define QUAD_REAL_FPOFLOW 4
78 #define QUAD_REAL_NERR 4
79 #define QUAD_REAL_EINV (QUAD_REAL_NERR + 1)
80 int sigerr_quad_real (int errcond, int errcode, const char *where);
81 #endif
82
83 #if (FLT256_LEN == 15)
84 static const int QUAD_REAL_ITT_DIV = 3;
85 static const int QUAD_REAL_K_TANH = 6;
86 static const int QUAD_REAL_MS_EXP = 39;
87 static const int QUAD_REAL_MS_HYP = 45;
88 static const int QUAD_REAL_MS_TRG = 55;
89 #else
90 #error invalid real*32 length
91 #endif
92
93 #define QUAD_REAL_MAX_10EX 4931
94
95 extern const QUAD_T QUAD_REAL_EE;
96 extern const QUAD_T QUAD_REAL_FIXCORR;
97 extern const QUAD_T QUAD_REAL_HALF;
98 extern const QUAD_T QUAD_REAL_HUNDRED;
99 extern const QUAD_T QUAD_REAL_LN10;
100 extern const QUAD_T QUAD_REAL_LN2;
101 extern const QUAD_T QUAD_REAL_LOG10_E;
102 extern const QUAD_T QUAD_REAL_LOG2_10;
103 extern const QUAD_T QUAD_REAL_LOG2_E;
104 extern const QUAD_T QUAD_REAL_NAN;
105 extern const QUAD_T QUAD_REAL_ONE;
106 extern const QUAD_T QUAD_REAL_PI;
107 extern const QUAD_T QUAD_REAL_PI2;
108 extern const QUAD_T QUAD_REAL_PI4;
109 extern const QUAD_T QUAD_REAL_RNDCORR;
110 extern const QUAD_T QUAD_REAL_SQRT2;
111 extern const QUAD_T QUAD_REAL_TEN;
112 extern const QUAD_T QUAD_REAL_TENTH;
113 extern const QUAD_T QUAD_REAL_THOUSAND;
114 extern const QUAD_T QUAD_REAL_TWO;
115 extern const QUAD_T QUAD_REAL_ZERO;
116
117 extern const int_2 QUAD_REAL_BIAS;
118 extern const int_2 QUAD_REAL_DBL_BIAS;
119 extern const int_2 QUAD_REAL_DBL_LEX;
120 extern const int_2 QUAD_REAL_DBL_MAX;
121 extern const int_2 QUAD_REAL_K_LIN;
122 extern const int_2 QUAD_REAL_MAX_P;
123 extern const QUAD_T QUAD_REAL_E2MAX;
124 extern const QUAD_T QUAD_REAL_E2MIN;
125 extern const QUAD_T QUAD_REAL_EMAX;
126 extern const QUAD_T QUAD_REAL_EMIN;
127 extern const QUAD_T QUAD_REAL_MINF;
128 extern const QUAD_T QUAD_REAL_PINF;
129 extern const QUAD_T QUAD_REAL_VGV;
130 extern const QUAD_T QUAD_REAL_VSV;
131 extern const unt_2 QUAD_REAL_M_EXP;
132 extern const unt_2 QUAD_REAL_M_SIGN;
133
134 extern DOUBLE_T quad_real_to_double_real (QUAD_T);
135 extern int eq_quad_real (QUAD_T, QUAD_T);
136 extern int ge_quad_real (QUAD_T, QUAD_T);
137 extern int getexp_quad_real (const QUAD_T *);
138 extern int getsgn_quad_real (const QUAD_T *);
139 extern int gt_quad_real (QUAD_T, QUAD_T);
140 extern int is0_quad_real (const QUAD_T *);
141 extern int isMinf_quad_real (const QUAD_T *);
142 extern int isNaN_quad_real (const QUAD_T *);
143 extern int isordnumb_quad_real (const QUAD_T *);
144 extern int isPinf_quad_real (const QUAD_T *);
145 extern int le_quad_real (QUAD_T, QUAD_T);
146 extern int lt_quad_real (QUAD_T, QUAD_T);
147 extern int neq_quad_real (QUAD_T, QUAD_T);
148 extern int not0_quad_real (const QUAD_T *);
149 extern int real_cmp_quad_real (const QUAD_T *, const QUAD_T *);
150 extern int sgn_quad_real (const QUAD_T *);
151 extern QUAD_T abs_quad_real (QUAD_T);
152 extern QUAD_T acosh_quad_real (QUAD_T);
153 extern QUAD_T acos_quad_real (QUAD_T);
154 extern QUAD_T acotan_quad_real (QUAD_T);
155 extern QUAD_T add_quad_real (QUAD_T, QUAD_T, int);
156 extern QUAD_T aint_quad_real (QUAD_T);
157 extern QUAD_T asinh_quad_real (QUAD_T);
158 extern QUAD_T asin_quad_real (QUAD_T);
159 extern QUAD_T atan2_quad_real (QUAD_T, QUAD_T);
160 extern QUAD_T atanh_quad_real (QUAD_T);
161 extern QUAD_T atan_quad_real (QUAD_T);
162 extern QUAD_T atox (const char *);
163 extern QUAD_T ceil_quad_real (QUAD_T);
164 extern QUAD_T* chcof_quad_real (int, QUAD_T (*) (QUAD_T));
165 extern QUAD_T cosh_quad_real (QUAD_T);
166 extern QUAD_T cos_quad_real (QUAD_T);
167 extern QUAD_T cotan_quad_real (QUAD_T);
168 extern QUAD_T div_quad_real (QUAD_T, QUAD_T);
169 extern QUAD_T double_real_to_quad_real (DOUBLE_T);
170 extern QUAD_T evtch_quad_real (QUAD_T, QUAD_T *, int);
171 extern QUAD_T exp10_quad_real (QUAD_T);
172 extern QUAD_T exp2_quad_real (QUAD_T);
173 extern QUAD_T exp_quad_real (QUAD_T);
174 extern QUAD_T fix_quad_real (QUAD_T);
175 extern QUAD_T floor_quad_real (QUAD_T);
176 extern QUAD_T fmod_quad_real (QUAD_T, QUAD_T, QUAD_T *);
177 extern QUAD_T frac_quad_real (QUAD_T);
178 extern QUAD_T frexp_quad_real (QUAD_T, int *);
179 extern QUAD_T int_to_quad_real (int);
180 extern QUAD_T log10_quad_real (QUAD_T);
181 extern QUAD_T log2_quad_real (QUAD_T);
182 extern QUAD_T log_quad_real (QUAD_T);
183 extern QUAD_T max_quad_real_2 (QUAD_T, QUAD_T);
184 extern QUAD_T min_quad_real_2 (QUAD_T, QUAD_T);
185 extern QUAD_T mul_quad_real (QUAD_T, QUAD_T);
186 extern QUAD_T neg_quad_real (QUAD_T);
187 extern QUAD_T nint_quad_real (QUAD_T);
188 extern QUAD_T pow_quad_real (QUAD_T, QUAD_T);
189 extern QUAD_T pwr_quad_real (QUAD_T, int);
190 extern QUAD_T real_2_quad_real (QUAD_T, int);
191 extern QUAD_T real_to_quad_real (REAL_T);
192 extern QUAD_T round_quad_real (QUAD_T);
193 extern QUAD_T sfmod_quad_real (QUAD_T, int *);
194 extern QUAD_T sgn_quad_real_2 (QUAD_T, QUAD_T);
195 extern QUAD_T sinh_quad_real (QUAD_T);
196 extern QUAD_T sin_quad_real (QUAD_T);
197 extern QUAD_T sqrt_quad_real (QUAD_T);
198 extern QUAD_T string_to_quad_real (const char *, char **);
199 extern QUAD_T tanh_quad_real (QUAD_T);
200 extern QUAD_T tan_quad_real (QUAD_T);
201 extern QUAD_T ten_up_quad_real (int);
202 extern QUAD_T trunc_quad_real (QUAD_T);
203 extern REAL_T quad_real_to_real (QUAD_T);
204 extern void lshift_quad_real (int, unt_2 *, int);
205 extern void rshift_quad_real (int, unt_2 *, int);
206
207 #endif
208 #endif