]> git.ipfire.org Git - thirdparty/gcc.git/blame - libdecnumber/decContext.h
Make TOPN counter dynamically allocated.
[thirdparty/gcc.git] / libdecnumber / decContext.h
CommitLineData
2533577f 1/* Decimal context header module for the decNumber C Library.
8d9254fc 2 Copyright (C) 2005-2020 Free Software Foundation, Inc.
473a74b9
BE
3 Contributed by IBM Corporation. Author Mike Cowlishaw.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
748086b7 9 Software Foundation; either version 3, or (at your option) any later
473a74b9
BE
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
473a74b9
BE
25
26/* ------------------------------------------------------------------ */
2533577f
JJ
27/* Decimal Context module header */
28/* ------------------------------------------------------------------ */
29/* */
30/* Context variables must always have valid values: */
31/* */
7bd36a9c 32/* status -- [any bits may be cleared, but not set, by user] */
2533577f
JJ
33/* round -- must be one of the enumerated rounding modes */
34/* */
35/* The following variables are implied for fixed size formats (i.e., */
36/* they are ignored) but should still be set correctly in case used */
37/* with decNumber functions: */
38/* */
39/* clamp -- must be either 0 or 1 */
40/* digits -- must be in the range 1 through 999999999 */
41/* emax -- must be in the range 0 through 999999999 */
42/* emin -- must be in the range 0 through -999999999 */
473a74b9 43/* extended -- must be either 0 or 1 [present only if DECSUBSET] */
2533577f
JJ
44/* traps -- only defined bits may be set */
45/* */
473a74b9
BE
46/* ------------------------------------------------------------------ */
47
48#if !defined(DECCONTEXT)
2533577f
JJ
49 #define DECCONTEXT
50 #define DECCNAME "decContext" /* Short name */
51 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
7bd36a9c 52 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
473a74b9 53
9daa490d 54 #include "gstdint.h" /* C99 standard integers */
2533577f 55 #include <stdio.h> /* for printf, etc. */
7bd36a9c 56 #include <signal.h> /* for traps */
2533577f
JJ
57
58 /* Extended flags setting -- set this to 0 to use only IEEE flags */
7bd36a9c 59 #if !defined(DECEXTFLAG)
2533577f 60 #define DECEXTFLAG 1 /* 1=enable extended flags */
7bd36a9c 61 #endif
2533577f
JJ
62
63 /* Conditional code flag -- set this to 0 for best performance */
7bd36a9c 64 #if !defined(DECSUBSET)
2533577f 65 #define DECSUBSET 0 /* 1=enable subset arithmetic */
7bd36a9c 66 #endif
2533577f
JJ
67
68 /* Context for operations, with associated constants */
69 enum rounding {
70 DEC_ROUND_CEILING, /* round towards +infinity */
7bd36a9c 71 DEC_ROUND_UP, /* round away from 0 */
2533577f
JJ
72 DEC_ROUND_HALF_UP, /* 0.5 rounds up */
73 DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
74 DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
75 DEC_ROUND_DOWN, /* round towards 0 (truncate) */
76 DEC_ROUND_FLOOR, /* round towards -infinity */
7bd36a9c 77 DEC_ROUND_05UP, /* round for reround */
2533577f
JJ
78 DEC_ROUND_MAX /* enum must be less than this */
79 };
80 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
81
82 typedef struct {
7bd36a9c
BE
83 int32_t digits; /* working precision */
84 int32_t emax; /* maximum positive exponent */
85 int32_t emin; /* minimum negative exponent */
2533577f
JJ
86 enum rounding round; /* rounding mode */
87 uint32_t traps; /* trap-enabler flags */
88 uint32_t status; /* status flags */
89 uint8_t clamp; /* flag: apply IEEE exponent clamp */
90 #if DECSUBSET
91 uint8_t extended; /* flag: special-values allowed */
92 #endif
93 } decContext;
94
95 /* Maxima and Minima for context settings */
96 #define DEC_MAX_DIGITS 999999999
97 #define DEC_MIN_DIGITS 1
98 #define DEC_MAX_EMAX 999999999
99 #define DEC_MIN_EMAX 0
100 #define DEC_MAX_EMIN 0
101 #define DEC_MIN_EMIN -999999999
102 #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
103
7bd36a9c
BE
104 /* Classifications for decimal numbers, aligned with 754 (note that */
105 /* 'normal' and 'subnormal' are meaningful only with a decContext */
106 /* or a fixed size format). */
2533577f
JJ
107 enum decClass {
108 DEC_CLASS_SNAN,
109 DEC_CLASS_QNAN,
110 DEC_CLASS_NEG_INF,
111 DEC_CLASS_NEG_NORMAL,
112 DEC_CLASS_NEG_SUBNORMAL,
113 DEC_CLASS_NEG_ZERO,
114 DEC_CLASS_POS_ZERO,
115 DEC_CLASS_POS_SUBNORMAL,
116 DEC_CLASS_POS_NORMAL,
117 DEC_CLASS_POS_INF
118 };
119 /* Strings for the decClasses */
120 #define DEC_ClassString_SN "sNaN"
121 #define DEC_ClassString_QN "NaN"
122 #define DEC_ClassString_NI "-Infinity"
123 #define DEC_ClassString_NN "-Normal"
124 #define DEC_ClassString_NS "-Subnormal"
125 #define DEC_ClassString_NZ "-Zero"
126 #define DEC_ClassString_PZ "+Zero"
127 #define DEC_ClassString_PS "+Subnormal"
128 #define DEC_ClassString_PN "+Normal"
129 #define DEC_ClassString_PI "+Infinity"
130 #define DEC_ClassString_UN "Invalid"
131
132 /* Trap-enabler and Status flags (exceptional conditions), and */
133 /* their names. The top byte is reserved for internal use */
134 #if DECEXTFLAG
135 /* Extended flags */
136 #define DEC_Conversion_syntax 0x00000001
137 #define DEC_Division_by_zero 0x00000002
138 #define DEC_Division_impossible 0x00000004
139 #define DEC_Division_undefined 0x00000008
140 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
7bd36a9c
BE
141 #define DEC_Inexact 0x00000020
142 #define DEC_Invalid_context 0x00000040
2533577f
JJ
143 #define DEC_Invalid_operation 0x00000080
144 #if DECSUBSET
145 #define DEC_Lost_digits 0x00000100
146 #endif
147 #define DEC_Overflow 0x00000200
7bd36a9c
BE
148 #define DEC_Clamped 0x00000400
149 #define DEC_Rounded 0x00000800
2533577f
JJ
150 #define DEC_Subnormal 0x00001000
151 #define DEC_Underflow 0x00002000
152 #else
153 /* IEEE flags only */
154 #define DEC_Conversion_syntax 0x00000010
155 #define DEC_Division_by_zero 0x00000002
156 #define DEC_Division_impossible 0x00000010
157 #define DEC_Division_undefined 0x00000010
158 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
7bd36a9c
BE
159 #define DEC_Inexact 0x00000001
160 #define DEC_Invalid_context 0x00000010
2533577f
JJ
161 #define DEC_Invalid_operation 0x00000010
162 #if DECSUBSET
163 #define DEC_Lost_digits 0x00000000
164 #endif
165 #define DEC_Overflow 0x00000008
7bd36a9c
BE
166 #define DEC_Clamped 0x00000000
167 #define DEC_Rounded 0x00000000
2533577f
JJ
168 #define DEC_Subnormal 0x00000000
169 #define DEC_Underflow 0x00000004
170 #endif
171
7bd36a9c 172 /* IEEE 754 groupings for the flags */
2533577f 173 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
7bd36a9c
BE
174 /* are not in IEEE 754] */
175 #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
2533577f 176 #if DECSUBSET
7bd36a9c 177 #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
2533577f 178 #else
7bd36a9c 179 #define DEC_IEEE_754_Inexact (DEC_Inexact)
2533577f 180 #endif
7bd36a9c 181 #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
2533577f
JJ
182 DEC_Division_impossible | \
183 DEC_Division_undefined | \
184 DEC_Insufficient_storage | \
7bd36a9c 185 DEC_Invalid_context | \
2533577f 186 DEC_Invalid_operation)
7bd36a9c
BE
187 #define DEC_IEEE_754_Overflow (DEC_Overflow)
188 #define DEC_IEEE_754_Underflow (DEC_Underflow)
2533577f
JJ
189
190 /* flags which are normally errors (result is qNaN, infinite, or 0) */
7bd36a9c
BE
191 #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
192 DEC_IEEE_754_Invalid_operation | \
193 DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
2533577f 194 /* flags which cause a result to become qNaN */
7bd36a9c 195 #define DEC_NaNs DEC_IEEE_754_Invalid_operation
2533577f
JJ
196
197 /* flags which are normally for information only (finite results) */
198 #if DECSUBSET
199 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
200 | DEC_Lost_digits)
201 #else
202 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
203 #endif
204
7bd36a9c
BE
205 /* IEEE 854 names (for compatibility with older decNumber versions) */
206 #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
207 #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
208 #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
209 #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
210 #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
211
2533577f
JJ
212 /* Name strings for the exceptional conditions */
213 #define DEC_Condition_CS "Conversion syntax"
214 #define DEC_Condition_DZ "Division by zero"
215 #define DEC_Condition_DI "Division impossible"
216 #define DEC_Condition_DU "Division undefined"
217 #define DEC_Condition_IE "Inexact"
218 #define DEC_Condition_IS "Insufficient storage"
219 #define DEC_Condition_IC "Invalid context"
220 #define DEC_Condition_IO "Invalid operation"
221 #if DECSUBSET
222 #define DEC_Condition_LD "Lost digits"
223 #endif
224 #define DEC_Condition_OV "Overflow"
225 #define DEC_Condition_PA "Clamped"
226 #define DEC_Condition_RO "Rounded"
227 #define DEC_Condition_SU "Subnormal"
228 #define DEC_Condition_UN "Underflow"
229 #define DEC_Condition_ZE "No status"
230 #define DEC_Condition_MU "Multiple status"
231 #define DEC_Condition_Length 21 /* length of the longest string, */
232 /* including terminator */
233
234 /* Initialization descriptors, used by decContextDefault */
7bd36a9c 235 #define DEC_INIT_BASE 0
2533577f
JJ
236 #define DEC_INIT_DECIMAL32 32
237 #define DEC_INIT_DECIMAL64 64
238 #define DEC_INIT_DECIMAL128 128
239 /* Synonyms */
240 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
241 #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
242 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
243
244 /* decContext routines */
245
246 #include "decContextSymbols.h"
247
6863c0f0
ILT
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
251
2533577f
JJ
252 extern decContext * decContextClearStatus(decContext *, uint32_t);
253 extern decContext * decContextDefault(decContext *, int32_t);
254 extern enum rounding decContextGetRounding(decContext *);
255 extern uint32_t decContextGetStatus(decContext *);
256 extern decContext * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
257 extern uint32_t decContextSaveStatus(decContext *, uint32_t);
258 extern decContext * decContextSetRounding(decContext *, enum rounding);
259 extern decContext * decContextSetStatus(decContext *, uint32_t);
260 extern decContext * decContextSetStatusFromString(decContext *, const char *);
261 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
262 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
263 extern const char * decContextStatusToString(const decContext *);
7bd36a9c 264 extern int32_t decContextTestEndian(uint8_t);
2533577f
JJ
265 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
266 extern uint32_t decContextTestStatus(decContext *, uint32_t);
267 extern decContext * decContextZeroStatus(decContext *);
473a74b9 268
6863c0f0
ILT
269 #ifdef __cplusplus
270 }
271 #endif
272
473a74b9 273#endif