comparison libdecnumber/decContext.h @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children 04ced10e8804
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
27 /* Decimal Context module header */ 27 /* Decimal Context module header */
28 /* ------------------------------------------------------------------ */ 28 /* ------------------------------------------------------------------ */
29 /* */ 29 /* */
30 /* Context variables must always have valid values: */ 30 /* Context variables must always have valid values: */
31 /* */ 31 /* */
32 /* status -- [any bits may be cleared, but not set, by user] */ 32 /* status -- [any bits may be cleared, but not set, by user] */
33 /* round -- must be one of the enumerated rounding modes */ 33 /* round -- must be one of the enumerated rounding modes */
34 /* */ 34 /* */
35 /* The following variables are implied for fixed size formats (i.e., */ 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 */ 36 /* they are ignored) but should still be set correctly in case used */
37 /* with decNumber functions: */ 37 /* with decNumber functions: */
47 47
48 #if !defined(DECCONTEXT) 48 #if !defined(DECCONTEXT)
49 #define DECCONTEXT 49 #define DECCONTEXT
50 #define DECCNAME "decContext" /* Short name */ 50 #define DECCNAME "decContext" /* Short name */
51 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */ 51 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
52 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */ 52 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
53 53
54 #include "gstdint.h" /* C99 standard integers */ 54 #include "gstdint.h" /* C99 standard integers */
55 #include <stdio.h> /* for printf, etc. */ 55 #include <stdio.h> /* for printf, etc. */
56 #include <signal.h> /* for traps */ 56 #include <signal.h> /* for traps */
57 57
58 /* Extended flags setting -- set this to 0 to use only IEEE flags */ 58 /* Extended flags setting -- set this to 0 to use only IEEE flags */
59 #if !defined(DECEXTFLAG)
59 #define DECEXTFLAG 1 /* 1=enable extended flags */ 60 #define DECEXTFLAG 1 /* 1=enable extended flags */
61 #endif
60 62
61 /* Conditional code flag -- set this to 0 for best performance */ 63 /* Conditional code flag -- set this to 0 for best performance */
64 #if !defined(DECSUBSET)
62 #define DECSUBSET 0 /* 1=enable subset arithmetic */ 65 #define DECSUBSET 0 /* 1=enable subset arithmetic */
66 #endif
63 67
64 /* Context for operations, with associated constants */ 68 /* Context for operations, with associated constants */
65 enum rounding { 69 enum rounding {
66 DEC_ROUND_CEILING, /* round towards +infinity */ 70 DEC_ROUND_CEILING, /* round towards +infinity */
67 DEC_ROUND_UP, /* round away from 0 */ 71 DEC_ROUND_UP, /* round away from 0 */
68 DEC_ROUND_HALF_UP, /* 0.5 rounds up */ 72 DEC_ROUND_HALF_UP, /* 0.5 rounds up */
69 DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */ 73 DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
70 DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */ 74 DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
71 DEC_ROUND_DOWN, /* round towards 0 (truncate) */ 75 DEC_ROUND_DOWN, /* round towards 0 (truncate) */
72 DEC_ROUND_FLOOR, /* round towards -infinity */ 76 DEC_ROUND_FLOOR, /* round towards -infinity */
73 DEC_ROUND_05UP, /* round for reround */ 77 DEC_ROUND_05UP, /* round for reround */
74 DEC_ROUND_MAX /* enum must be less than this */ 78 DEC_ROUND_MAX /* enum must be less than this */
75 }; 79 };
76 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN; 80 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
77 81
78 typedef struct { 82 typedef struct {
79 int32_t digits; /* working precision */ 83 int32_t digits; /* working precision */
80 int32_t emax; /* maximum positive exponent */ 84 int32_t emax; /* maximum positive exponent */
81 int32_t emin; /* minimum negative exponent */ 85 int32_t emin; /* minimum negative exponent */
82 enum rounding round; /* rounding mode */ 86 enum rounding round; /* rounding mode */
83 uint32_t traps; /* trap-enabler flags */ 87 uint32_t traps; /* trap-enabler flags */
84 uint32_t status; /* status flags */ 88 uint32_t status; /* status flags */
85 uint8_t clamp; /* flag: apply IEEE exponent clamp */ 89 uint8_t clamp; /* flag: apply IEEE exponent clamp */
86 #if DECSUBSET 90 #if DECSUBSET
95 #define DEC_MIN_EMAX 0 99 #define DEC_MIN_EMAX 0
96 #define DEC_MAX_EMIN 0 100 #define DEC_MAX_EMIN 0
97 #define DEC_MIN_EMIN -999999999 101 #define DEC_MIN_EMIN -999999999
98 #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */ 102 #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
99 103
100 /* Classifications for decimal numbers, aligned with 754r (note */ 104 /* Classifications for decimal numbers, aligned with 754 (note that */
101 /* that 'normal' and 'subnormal' are meaningful only with a */ 105 /* 'normal' and 'subnormal' are meaningful only with a decContext */
102 /* decContext or a fixed size format). */ 106 /* or a fixed size format). */
103 enum decClass { 107 enum decClass {
104 DEC_CLASS_SNAN, 108 DEC_CLASS_SNAN,
105 DEC_CLASS_QNAN, 109 DEC_CLASS_QNAN,
106 DEC_CLASS_NEG_INF, 110 DEC_CLASS_NEG_INF,
107 DEC_CLASS_NEG_NORMAL, 111 DEC_CLASS_NEG_NORMAL,
132 #define DEC_Conversion_syntax 0x00000001 136 #define DEC_Conversion_syntax 0x00000001
133 #define DEC_Division_by_zero 0x00000002 137 #define DEC_Division_by_zero 0x00000002
134 #define DEC_Division_impossible 0x00000004 138 #define DEC_Division_impossible 0x00000004
135 #define DEC_Division_undefined 0x00000008 139 #define DEC_Division_undefined 0x00000008
136 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */ 140 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
137 #define DEC_Inexact 0x00000020 141 #define DEC_Inexact 0x00000020
138 #define DEC_Invalid_context 0x00000040 142 #define DEC_Invalid_context 0x00000040
139 #define DEC_Invalid_operation 0x00000080 143 #define DEC_Invalid_operation 0x00000080
140 #if DECSUBSET 144 #if DECSUBSET
141 #define DEC_Lost_digits 0x00000100 145 #define DEC_Lost_digits 0x00000100
142 #endif 146 #endif
143 #define DEC_Overflow 0x00000200 147 #define DEC_Overflow 0x00000200
144 #define DEC_Clamped 0x00000400 148 #define DEC_Clamped 0x00000400
145 #define DEC_Rounded 0x00000800 149 #define DEC_Rounded 0x00000800
146 #define DEC_Subnormal 0x00001000 150 #define DEC_Subnormal 0x00001000
147 #define DEC_Underflow 0x00002000 151 #define DEC_Underflow 0x00002000
148 #else 152 #else
149 /* IEEE flags only */ 153 /* IEEE flags only */
150 #define DEC_Conversion_syntax 0x00000010 154 #define DEC_Conversion_syntax 0x00000010
151 #define DEC_Division_by_zero 0x00000002 155 #define DEC_Division_by_zero 0x00000002
152 #define DEC_Division_impossible 0x00000010 156 #define DEC_Division_impossible 0x00000010
153 #define DEC_Division_undefined 0x00000010 157 #define DEC_Division_undefined 0x00000010
154 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */ 158 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
155 #define DEC_Inexact 0x00000001 159 #define DEC_Inexact 0x00000001
156 #define DEC_Invalid_context 0x00000010 160 #define DEC_Invalid_context 0x00000010
157 #define DEC_Invalid_operation 0x00000010 161 #define DEC_Invalid_operation 0x00000010
158 #if DECSUBSET 162 #if DECSUBSET
159 #define DEC_Lost_digits 0x00000000 163 #define DEC_Lost_digits 0x00000000
160 #endif 164 #endif
161 #define DEC_Overflow 0x00000008 165 #define DEC_Overflow 0x00000008
162 #define DEC_Clamped 0x00000000 166 #define DEC_Clamped 0x00000000
163 #define DEC_Rounded 0x00000000 167 #define DEC_Rounded 0x00000000
164 #define DEC_Subnormal 0x00000000 168 #define DEC_Subnormal 0x00000000
165 #define DEC_Underflow 0x00000004 169 #define DEC_Underflow 0x00000004
166 #endif 170 #endif
167 171
168 /* IEEE 854 groupings for the flags */ 172 /* IEEE 754 groupings for the flags */
169 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */ 173 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
170 /* are not in IEEE 854] */ 174 /* are not in IEEE 754] */
171 #define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero) 175 #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
172 #if DECSUBSET 176 #if DECSUBSET
173 #define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits) 177 #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
174 #else 178 #else
175 #define DEC_IEEE_854_Inexact (DEC_Inexact) 179 #define DEC_IEEE_754_Inexact (DEC_Inexact)
176 #endif 180 #endif
177 #define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \ 181 #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
178 DEC_Division_impossible | \ 182 DEC_Division_impossible | \
179 DEC_Division_undefined | \ 183 DEC_Division_undefined | \
180 DEC_Insufficient_storage | \ 184 DEC_Insufficient_storage | \
181 DEC_Invalid_context | \ 185 DEC_Invalid_context | \
182 DEC_Invalid_operation) 186 DEC_Invalid_operation)
183 #define DEC_IEEE_854_Overflow (DEC_Overflow) 187 #define DEC_IEEE_754_Overflow (DEC_Overflow)
184 #define DEC_IEEE_854_Underflow (DEC_Underflow) 188 #define DEC_IEEE_754_Underflow (DEC_Underflow)
185 189
186 /* flags which are normally errors (result is qNaN, infinite, or 0) */ 190 /* flags which are normally errors (result is qNaN, infinite, or 0) */
187 #define DEC_Errors (DEC_IEEE_854_Division_by_zero | \ 191 #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
188 DEC_IEEE_854_Invalid_operation | \ 192 DEC_IEEE_754_Invalid_operation | \
189 DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow) 193 DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
190 /* flags which cause a result to become qNaN */ 194 /* flags which cause a result to become qNaN */
191 #define DEC_NaNs DEC_IEEE_854_Invalid_operation 195 #define DEC_NaNs DEC_IEEE_754_Invalid_operation
192 196
193 /* flags which are normally for information only (finite results) */ 197 /* flags which are normally for information only (finite results) */
194 #if DECSUBSET 198 #if DECSUBSET
195 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \ 199 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
196 | DEC_Lost_digits) 200 | DEC_Lost_digits)
197 #else 201 #else
198 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact) 202 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
199 #endif 203 #endif
204
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
200 211
201 /* Name strings for the exceptional conditions */ 212 /* Name strings for the exceptional conditions */
202 #define DEC_Condition_CS "Conversion syntax" 213 #define DEC_Condition_CS "Conversion syntax"
203 #define DEC_Condition_DZ "Division by zero" 214 #define DEC_Condition_DZ "Division by zero"
204 #define DEC_Condition_DI "Division impossible" 215 #define DEC_Condition_DI "Division impossible"
219 #define DEC_Condition_MU "Multiple status" 230 #define DEC_Condition_MU "Multiple status"
220 #define DEC_Condition_Length 21 /* length of the longest string, */ 231 #define DEC_Condition_Length 21 /* length of the longest string, */
221 /* including terminator */ 232 /* including terminator */
222 233
223 /* Initialization descriptors, used by decContextDefault */ 234 /* Initialization descriptors, used by decContextDefault */
224 #define DEC_INIT_BASE 0 235 #define DEC_INIT_BASE 0
225 #define DEC_INIT_DECIMAL32 32 236 #define DEC_INIT_DECIMAL32 32
226 #define DEC_INIT_DECIMAL64 64 237 #define DEC_INIT_DECIMAL64 64
227 #define DEC_INIT_DECIMAL128 128 238 #define DEC_INIT_DECIMAL128 128
228 /* Synonyms */ 239 /* Synonyms */
229 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32 240 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
231 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128 242 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
232 243
233 /* decContext routines */ 244 /* decContext routines */
234 245
235 #include "decContextSymbols.h" 246 #include "decContextSymbols.h"
247
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
236 251
237 extern decContext * decContextClearStatus(decContext *, uint32_t); 252 extern decContext * decContextClearStatus(decContext *, uint32_t);
238 extern decContext * decContextDefault(decContext *, int32_t); 253 extern decContext * decContextDefault(decContext *, int32_t);
239 extern enum rounding decContextGetRounding(decContext *); 254 extern enum rounding decContextGetRounding(decContext *);
240 extern uint32_t decContextGetStatus(decContext *); 255 extern uint32_t decContextGetStatus(decContext *);
244 extern decContext * decContextSetStatus(decContext *, uint32_t); 259 extern decContext * decContextSetStatus(decContext *, uint32_t);
245 extern decContext * decContextSetStatusFromString(decContext *, const char *); 260 extern decContext * decContextSetStatusFromString(decContext *, const char *);
246 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *); 261 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
247 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t); 262 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
248 extern const char * decContextStatusToString(const decContext *); 263 extern const char * decContextStatusToString(const decContext *);
264 extern int32_t decContextTestEndian(uint8_t);
249 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t); 265 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
250 extern uint32_t decContextTestStatus(decContext *, uint32_t); 266 extern uint32_t decContextTestStatus(decContext *, uint32_t);
251 extern decContext * decContextZeroStatus(decContext *); 267 extern decContext * decContextZeroStatus(decContext *);
252 268
269 #ifdef __cplusplus
270 }
271 #endif
272
253 #endif 273 #endif