Mercurial > hg > CbC > CbC_gcc
annotate libdecnumber/decContext.h @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
rev | line source |
---|---|
0 | 1 /* Decimal context header module for the decNumber C Library. |
145 | 2 Copyright (C) 2005-2020 Free Software Foundation, Inc. |
0 | 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 | |
9 Software Foundation; either version 3, or (at your option) any later | |
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 | |
17 Under Section 7 of GPL version 3, you are granted additional | |
18 permissions described in the GCC Runtime Library Exception, version | |
19 3.1, as published by the Free Software Foundation. | |
20 | |
21 You should have received a copy of the GNU General Public License and | |
22 a copy of the GCC Runtime Library Exception along with this program; | |
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 <http://www.gnu.org/licenses/>. */ | |
25 | |
26 /* ------------------------------------------------------------------ */ | |
27 /* Decimal Context module header */ | |
28 /* ------------------------------------------------------------------ */ | |
29 /* */ | |
30 /* Context variables must always have valid values: */ | |
31 /* */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
32 /* status -- [any bits may be cleared, but not set, by user] */ |
0 | 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 */ | |
43 /* extended -- must be either 0 or 1 [present only if DECSUBSET] */ | |
44 /* traps -- only defined bits may be set */ | |
45 /* */ | |
46 /* ------------------------------------------------------------------ */ | |
47 | |
48 #if !defined(DECCONTEXT) | |
49 #define DECCONTEXT | |
50 #define DECCNAME "decContext" /* Short name */ | |
51 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
52 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */ |
0 | 53 |
54 #include "gstdint.h" /* C99 standard integers */ | |
55 #include <stdio.h> /* for printf, etc. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
56 #include <signal.h> /* for traps */ |
0 | 57 |
58 /* Extended flags setting -- set this to 0 to use only IEEE flags */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
59 #if !defined(DECEXTFLAG) |
0 | 60 #define DECEXTFLAG 1 /* 1=enable extended flags */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
61 #endif |
0 | 62 |
63 /* Conditional code flag -- set this to 0 for best performance */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
64 #if !defined(DECSUBSET) |
0 | 65 #define DECSUBSET 0 /* 1=enable subset arithmetic */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
66 #endif |
0 | 67 |
68 /* Context for operations, with associated constants */ | |
69 enum rounding { | |
70 DEC_ROUND_CEILING, /* round towards +infinity */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
71 DEC_ROUND_UP, /* round away from 0 */ |
0 | 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 */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
77 DEC_ROUND_05UP, /* round for reround */ |
0 | 78 DEC_ROUND_MAX /* enum must be less than this */ |
79 }; | |
80 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN; | |
81 | |
82 typedef struct { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
83 int32_t digits; /* working precision */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
84 int32_t emax; /* maximum positive exponent */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
85 int32_t emin; /* minimum negative exponent */ |
0 | 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 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
104 /* Classifications for decimal numbers, aligned with 754 (note that */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
105 /* 'normal' and 'subnormal' are meaningful only with a decContext */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
106 /* or a fixed size format). */ |
0 | 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] */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
141 #define DEC_Inexact 0x00000020 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
142 #define DEC_Invalid_context 0x00000040 |
0 | 143 #define DEC_Invalid_operation 0x00000080 |
144 #if DECSUBSET | |
145 #define DEC_Lost_digits 0x00000100 | |
146 #endif | |
147 #define DEC_Overflow 0x00000200 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
148 #define DEC_Clamped 0x00000400 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
149 #define DEC_Rounded 0x00000800 |
0 | 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] */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
159 #define DEC_Inexact 0x00000001 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
160 #define DEC_Invalid_context 0x00000010 |
0 | 161 #define DEC_Invalid_operation 0x00000010 |
162 #if DECSUBSET | |
163 #define DEC_Lost_digits 0x00000000 | |
164 #endif | |
165 #define DEC_Overflow 0x00000008 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
166 #define DEC_Clamped 0x00000000 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
167 #define DEC_Rounded 0x00000000 |
0 | 168 #define DEC_Subnormal 0x00000000 |
169 #define DEC_Underflow 0x00000004 | |
170 #endif | |
171 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
172 /* IEEE 754 groupings for the flags */ |
0 | 173 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
174 /* are not in IEEE 754] */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
175 #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero) |
0 | 176 #if DECSUBSET |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
177 #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits) |
0 | 178 #else |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
179 #define DEC_IEEE_754_Inexact (DEC_Inexact) |
0 | 180 #endif |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
181 #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \ |
0 | 182 DEC_Division_impossible | \ |
183 DEC_Division_undefined | \ | |
184 DEC_Insufficient_storage | \ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
185 DEC_Invalid_context | \ |
0 | 186 DEC_Invalid_operation) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
187 #define DEC_IEEE_754_Overflow (DEC_Overflow) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
188 #define DEC_IEEE_754_Underflow (DEC_Underflow) |
0 | 189 |
190 /* flags which are normally errors (result is qNaN, infinite, or 0) */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
191 #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
192 DEC_IEEE_754_Invalid_operation | \ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
193 DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow) |
0 | 194 /* flags which cause a result to become qNaN */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
195 #define DEC_NaNs DEC_IEEE_754_Invalid_operation |
0 | 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 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
205 /* IEEE 854 names (for compatibility with older decNumber versions) */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
206 #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
207 #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
208 #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
209 #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
210 #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
211 |
0 | 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 */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
235 #define DEC_INIT_BASE 0 |
0 | 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 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
248 #ifdef __cplusplus |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
249 extern "C" { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
250 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
251 |
0 | 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 *); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
264 extern int32_t decContextTestEndian(uint8_t); |
0 | 265 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t); |
266 extern uint32_t decContextTestStatus(decContext *, uint32_t); | |
267 extern decContext * decContextZeroStatus(decContext *); | |
268 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
269 #ifdef __cplusplus |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
270 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
271 #endif |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
272 |
0 | 273 #endif |