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