1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#ifndef DECCONTEXT_H
54#define DECCONTEXT_H
55
56 #define DECCNAME "decContext"
57 #define DECCFULLNAME "Decimal Context Descriptor"
58 #define DECCAUTHOR "Mike Cowlishaw"
59
60
61
62 #define DECEXTFLAG 1
63
64
65 #define DECSUBSET 0
66
67
68 enum rounding {
69 DEC_ROUND_CEILING,
70 DEC_ROUND_UP,
71 DEC_ROUND_HALF_UP,
72 DEC_ROUND_HALF_EVEN,
73 DEC_ROUND_HALF_DOWN,
74 DEC_ROUND_DOWN,
75 DEC_ROUND_FLOOR,
76 DEC_ROUND_05UP,
77 DEC_ROUND_MAX
78 };
79 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
80
81 typedef struct {
82 int32_t digits;
83 int32_t emax;
84 int32_t emin;
85 enum rounding round;
86 uint32_t traps;
87 uint32_t status;
88 uint8_t clamp;
89 #if DECSUBSET
90 uint8_t extended;
91 #endif
92 } decContext;
93
94
95 #define DEC_MAX_DIGITS 999999999
96 #define DEC_MIN_DIGITS 1
97 #define DEC_MAX_EMAX 999999999
98 #define DEC_MIN_EMAX 0
99 #define DEC_MAX_EMIN 0
100 #define DEC_MIN_EMIN -999999999
101 #define DEC_MAX_MATH 999999
102
103
104
105
106 enum decClass {
107 DEC_CLASS_SNAN,
108 DEC_CLASS_QNAN,
109 DEC_CLASS_NEG_INF,
110 DEC_CLASS_NEG_NORMAL,
111 DEC_CLASS_NEG_SUBNORMAL,
112 DEC_CLASS_NEG_ZERO,
113 DEC_CLASS_POS_ZERO,
114 DEC_CLASS_POS_SUBNORMAL,
115 DEC_CLASS_POS_NORMAL,
116 DEC_CLASS_POS_INF
117 };
118
119 #define DEC_ClassString_SN "sNaN"
120 #define DEC_ClassString_QN "NaN"
121 #define DEC_ClassString_NI "-Infinity"
122 #define DEC_ClassString_NN "-Normal"
123 #define DEC_ClassString_NS "-Subnormal"
124 #define DEC_ClassString_NZ "-Zero"
125 #define DEC_ClassString_PZ "+Zero"
126 #define DEC_ClassString_PS "+Subnormal"
127 #define DEC_ClassString_PN "+Normal"
128 #define DEC_ClassString_PI "+Infinity"
129 #define DEC_ClassString_UN "Invalid"
130
131
132
133 #if DECEXTFLAG
134
135 #define DEC_Conversion_syntax 0x00000001
136 #define DEC_Division_by_zero 0x00000002
137 #define DEC_Division_impossible 0x00000004
138 #define DEC_Division_undefined 0x00000008
139 #define DEC_Insufficient_storage 0x00000010
140 #define DEC_Inexact 0x00000020
141 #define DEC_Invalid_context 0x00000040
142 #define DEC_Invalid_operation 0x00000080
143 #if DECSUBSET
144 #define DEC_Lost_digits 0x00000100
145 #endif
146 #define DEC_Overflow 0x00000200
147 #define DEC_Clamped 0x00000400
148 #define DEC_Rounded 0x00000800
149 #define DEC_Subnormal 0x00001000
150 #define DEC_Underflow 0x00002000
151 #else
152
153 #define DEC_Conversion_syntax 0x00000010
154 #define DEC_Division_by_zero 0x00000002
155 #define DEC_Division_impossible 0x00000010
156 #define DEC_Division_undefined 0x00000010
157 #define DEC_Insufficient_storage 0x00000010
158 #define DEC_Inexact 0x00000001
159 #define DEC_Invalid_context 0x00000010
160 #define DEC_Invalid_operation 0x00000010
161 #if DECSUBSET
162 #define DEC_Lost_digits 0x00000000
163 #endif
164 #define DEC_Overflow 0x00000008
165 #define DEC_Clamped 0x00000000
166 #define DEC_Rounded 0x00000000
167 #define DEC_Subnormal 0x00000000
168 #define DEC_Underflow 0x00000004
169 #endif
170
171
172
173
174 #define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero)
175 #if DECSUBSET
176 #define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits)
177 #else
178 #define DEC_IEEE_854_Inexact (DEC_Inexact)
179 #endif
180 #define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \
181 DEC_Division_impossible | \
182 DEC_Division_undefined | \
183 DEC_Insufficient_storage | \
184 DEC_Invalid_context | \
185 DEC_Invalid_operation)
186 #define DEC_IEEE_854_Overflow (DEC_Overflow)
187 #define DEC_IEEE_854_Underflow (DEC_Underflow)
188
189
190 #define DEC_Errors (DEC_IEEE_854_Division_by_zero | \
191 DEC_IEEE_854_Invalid_operation | \
192 DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow)
193
194 #define DEC_NaNs DEC_IEEE_854_Invalid_operation
195
196
197 #if DECSUBSET
198 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
199 | DEC_Lost_digits)
200 #else
201 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
202 #endif
203
204
205 #define DEC_Condition_CS "Conversion syntax"
206 #define DEC_Condition_DZ "Division by zero"
207 #define DEC_Condition_DI "Division impossible"
208 #define DEC_Condition_DU "Division undefined"
209 #define DEC_Condition_IE "Inexact"
210 #define DEC_Condition_IS "Insufficient storage"
211 #define DEC_Condition_IC "Invalid context"
212 #define DEC_Condition_IO "Invalid operation"
213 #if DECSUBSET
214 #define DEC_Condition_LD "Lost digits"
215 #endif
216 #define DEC_Condition_OV "Overflow"
217 #define DEC_Condition_PA "Clamped"
218 #define DEC_Condition_RO "Rounded"
219 #define DEC_Condition_SU "Subnormal"
220 #define DEC_Condition_UN "Underflow"
221 #define DEC_Condition_ZE "No status"
222 #define DEC_Condition_MU "Multiple status"
223 #define DEC_Condition_Length 21
224
225
226
227 #define DEC_INIT_BASE 0
228 #define DEC_INIT_DECIMAL32 32
229 #define DEC_INIT_DECIMAL64 64
230 #define DEC_INIT_DECIMAL128 128
231
232 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
233 #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
234 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
235
236
237
238
239 extern decContext * decContextClearStatus(decContext *, uint32_t);
240 extern decContext * decContextDefault(decContext *, int32_t);
241 extern enum rounding decContextGetRounding(decContext *);
242 extern uint32_t decContextGetStatus(decContext *);
243 extern decContext * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
244 extern uint32_t decContextSaveStatus(decContext *, uint32_t);
245 extern decContext * decContextSetRounding(decContext *, enum rounding);
246 extern decContext * decContextSetStatus(decContext *, uint32_t);
247 extern decContext * decContextSetStatusFromString(decContext *, const char *);
248 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
249 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
250 extern const char * decContextStatusToString(const decContext *);
251 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
252 extern uint32_t decContextTestStatus(decContext *, uint32_t);
253 extern decContext * decContextZeroStatus(decContext *);
254
255#endif
256