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