Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* ------------------------------------------------------------------ */ |
michael@0 | 2 | /* Decimal Context module */ |
michael@0 | 3 | /* ------------------------------------------------------------------ */ |
michael@0 | 4 | /* Copyright (c) IBM Corporation, 2000-2012. All rights reserved. */ |
michael@0 | 5 | /* */ |
michael@0 | 6 | /* This software is made available under the terms of the */ |
michael@0 | 7 | /* ICU License -- ICU 1.8.1 and later. */ |
michael@0 | 8 | /* */ |
michael@0 | 9 | /* The description and User's Guide ("The decNumber C Library") for */ |
michael@0 | 10 | /* this software is called decNumber.pdf. This document is */ |
michael@0 | 11 | /* available, together with arithmetic and format specifications, */ |
michael@0 | 12 | /* testcases, and Web links, on the General Decimal Arithmetic page. */ |
michael@0 | 13 | /* */ |
michael@0 | 14 | /* Please send comments, suggestions, and corrections to the author: */ |
michael@0 | 15 | /* mfc@uk.ibm.com */ |
michael@0 | 16 | /* Mike Cowlishaw, IBM Fellow */ |
michael@0 | 17 | /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */ |
michael@0 | 18 | /* ------------------------------------------------------------------ */ |
michael@0 | 19 | /* This module comprises the routines for handling arithmetic */ |
michael@0 | 20 | /* context structures. */ |
michael@0 | 21 | /* ------------------------------------------------------------------ */ |
michael@0 | 22 | |
michael@0 | 23 | #include <string.h> /* for strcmp */ |
michael@0 | 24 | #include <stdio.h> /* for printf if DECCHECK */ |
michael@0 | 25 | #include "decContext.h" /* context and base types */ |
michael@0 | 26 | #include "decNumberLocal.h" /* decNumber local types, etc. */ |
michael@0 | 27 | |
michael@0 | 28 | #if 0 /* ICU: No need to test endianness at runtime. */ |
michael@0 | 29 | /* compile-time endian tester [assumes sizeof(Int)>1] */ |
michael@0 | 30 | static const Int mfcone=1; /* constant 1 */ |
michael@0 | 31 | static const Flag *mfctop=(Flag *)&mfcone; /* -> top byte */ |
michael@0 | 32 | #define LITEND *mfctop /* named flag; 1=little-endian */ |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | /* ------------------------------------------------------------------ */ |
michael@0 | 36 | /* decContextClearStatus -- clear bits in current status */ |
michael@0 | 37 | /* */ |
michael@0 | 38 | /* context is the context structure to be queried */ |
michael@0 | 39 | /* mask indicates the bits to be cleared (the status bit that */ |
michael@0 | 40 | /* corresponds to each 1 bit in the mask is cleared) */ |
michael@0 | 41 | /* returns context */ |
michael@0 | 42 | /* */ |
michael@0 | 43 | /* No error is possible. */ |
michael@0 | 44 | /* ------------------------------------------------------------------ */ |
michael@0 | 45 | U_CAPI decContext * U_EXPORT2 uprv_decContextClearStatus(decContext *context, uInt mask) { |
michael@0 | 46 | context->status&=~mask; |
michael@0 | 47 | return context; |
michael@0 | 48 | } /* decContextClearStatus */ |
michael@0 | 49 | |
michael@0 | 50 | /* ------------------------------------------------------------------ */ |
michael@0 | 51 | /* decContextDefault -- initialize a context structure */ |
michael@0 | 52 | /* */ |
michael@0 | 53 | /* context is the structure to be initialized */ |
michael@0 | 54 | /* kind selects the required set of default values, one of: */ |
michael@0 | 55 | /* DEC_INIT_BASE -- select ANSI X3-274 defaults */ |
michael@0 | 56 | /* DEC_INIT_DECIMAL32 -- select IEEE 754 defaults, 32-bit */ |
michael@0 | 57 | /* DEC_INIT_DECIMAL64 -- select IEEE 754 defaults, 64-bit */ |
michael@0 | 58 | /* DEC_INIT_DECIMAL128 -- select IEEE 754 defaults, 128-bit */ |
michael@0 | 59 | /* For any other value a valid context is returned, but with */ |
michael@0 | 60 | /* Invalid_operation set in the status field. */ |
michael@0 | 61 | /* returns a context structure with the appropriate initial values. */ |
michael@0 | 62 | /* ------------------------------------------------------------------ */ |
michael@0 | 63 | U_CAPI decContext * U_EXPORT2 uprv_decContextDefault(decContext *context, Int kind) { |
michael@0 | 64 | /* set defaults... */ |
michael@0 | 65 | context->digits=9; /* 9 digits */ |
michael@0 | 66 | context->emax=DEC_MAX_EMAX; /* 9-digit exponents */ |
michael@0 | 67 | context->emin=DEC_MIN_EMIN; /* .. balanced */ |
michael@0 | 68 | context->round=DEC_ROUND_HALF_UP; /* 0.5 rises */ |
michael@0 | 69 | context->traps=DEC_Errors; /* all but informational */ |
michael@0 | 70 | context->status=0; /* cleared */ |
michael@0 | 71 | context->clamp=0; /* no clamping */ |
michael@0 | 72 | #if DECSUBSET |
michael@0 | 73 | context->extended=0; /* cleared */ |
michael@0 | 74 | #endif |
michael@0 | 75 | switch (kind) { |
michael@0 | 76 | case DEC_INIT_BASE: |
michael@0 | 77 | /* [use defaults] */ |
michael@0 | 78 | break; |
michael@0 | 79 | case DEC_INIT_DECIMAL32: |
michael@0 | 80 | context->digits=7; /* digits */ |
michael@0 | 81 | context->emax=96; /* Emax */ |
michael@0 | 82 | context->emin=-95; /* Emin */ |
michael@0 | 83 | context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */ |
michael@0 | 84 | context->traps=0; /* no traps set */ |
michael@0 | 85 | context->clamp=1; /* clamp exponents */ |
michael@0 | 86 | #if DECSUBSET |
michael@0 | 87 | context->extended=1; /* set */ |
michael@0 | 88 | #endif |
michael@0 | 89 | break; |
michael@0 | 90 | case DEC_INIT_DECIMAL64: |
michael@0 | 91 | context->digits=16; /* digits */ |
michael@0 | 92 | context->emax=384; /* Emax */ |
michael@0 | 93 | context->emin=-383; /* Emin */ |
michael@0 | 94 | context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */ |
michael@0 | 95 | context->traps=0; /* no traps set */ |
michael@0 | 96 | context->clamp=1; /* clamp exponents */ |
michael@0 | 97 | #if DECSUBSET |
michael@0 | 98 | context->extended=1; /* set */ |
michael@0 | 99 | #endif |
michael@0 | 100 | break; |
michael@0 | 101 | case DEC_INIT_DECIMAL128: |
michael@0 | 102 | context->digits=34; /* digits */ |
michael@0 | 103 | context->emax=6144; /* Emax */ |
michael@0 | 104 | context->emin=-6143; /* Emin */ |
michael@0 | 105 | context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */ |
michael@0 | 106 | context->traps=0; /* no traps set */ |
michael@0 | 107 | context->clamp=1; /* clamp exponents */ |
michael@0 | 108 | #if DECSUBSET |
michael@0 | 109 | context->extended=1; /* set */ |
michael@0 | 110 | #endif |
michael@0 | 111 | break; |
michael@0 | 112 | |
michael@0 | 113 | default: /* invalid Kind */ |
michael@0 | 114 | /* use defaults, and .. */ |
michael@0 | 115 | uprv_decContextSetStatus(context, DEC_Invalid_operation); /* trap */ |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | return context;} /* decContextDefault */ |
michael@0 | 119 | |
michael@0 | 120 | /* ------------------------------------------------------------------ */ |
michael@0 | 121 | /* decContextGetRounding -- return current rounding mode */ |
michael@0 | 122 | /* */ |
michael@0 | 123 | /* context is the context structure to be queried */ |
michael@0 | 124 | /* returns the rounding mode */ |
michael@0 | 125 | /* */ |
michael@0 | 126 | /* No error is possible. */ |
michael@0 | 127 | /* ------------------------------------------------------------------ */ |
michael@0 | 128 | U_CAPI enum rounding U_EXPORT2 uprv_decContextGetRounding(decContext *context) { |
michael@0 | 129 | return context->round; |
michael@0 | 130 | } /* decContextGetRounding */ |
michael@0 | 131 | |
michael@0 | 132 | /* ------------------------------------------------------------------ */ |
michael@0 | 133 | /* decContextGetStatus -- return current status */ |
michael@0 | 134 | /* */ |
michael@0 | 135 | /* context is the context structure to be queried */ |
michael@0 | 136 | /* returns status */ |
michael@0 | 137 | /* */ |
michael@0 | 138 | /* No error is possible. */ |
michael@0 | 139 | /* ------------------------------------------------------------------ */ |
michael@0 | 140 | U_CAPI uInt U_EXPORT2 uprv_decContextGetStatus(decContext *context) { |
michael@0 | 141 | return context->status; |
michael@0 | 142 | } /* decContextGetStatus */ |
michael@0 | 143 | |
michael@0 | 144 | /* ------------------------------------------------------------------ */ |
michael@0 | 145 | /* decContextRestoreStatus -- restore bits in current status */ |
michael@0 | 146 | /* */ |
michael@0 | 147 | /* context is the context structure to be updated */ |
michael@0 | 148 | /* newstatus is the source for the bits to be restored */ |
michael@0 | 149 | /* mask indicates the bits to be restored (the status bit that */ |
michael@0 | 150 | /* corresponds to each 1 bit in the mask is set to the value of */ |
michael@0 | 151 | /* the correspnding bit in newstatus) */ |
michael@0 | 152 | /* returns context */ |
michael@0 | 153 | /* */ |
michael@0 | 154 | /* No error is possible. */ |
michael@0 | 155 | /* ------------------------------------------------------------------ */ |
michael@0 | 156 | U_CAPI decContext * U_EXPORT2 uprv_decContextRestoreStatus(decContext *context, |
michael@0 | 157 | uInt newstatus, uInt mask) { |
michael@0 | 158 | context->status&=~mask; /* clear the selected bits */ |
michael@0 | 159 | context->status|=(mask&newstatus); /* or in the new bits */ |
michael@0 | 160 | return context; |
michael@0 | 161 | } /* decContextRestoreStatus */ |
michael@0 | 162 | |
michael@0 | 163 | /* ------------------------------------------------------------------ */ |
michael@0 | 164 | /* decContextSaveStatus -- save bits in current status */ |
michael@0 | 165 | /* */ |
michael@0 | 166 | /* context is the context structure to be queried */ |
michael@0 | 167 | /* mask indicates the bits to be saved (the status bits that */ |
michael@0 | 168 | /* correspond to each 1 bit in the mask are saved) */ |
michael@0 | 169 | /* returns the AND of the mask and the current status */ |
michael@0 | 170 | /* */ |
michael@0 | 171 | /* No error is possible. */ |
michael@0 | 172 | /* ------------------------------------------------------------------ */ |
michael@0 | 173 | U_CAPI uInt U_EXPORT2 uprv_decContextSaveStatus(decContext *context, uInt mask) { |
michael@0 | 174 | return context->status&mask; |
michael@0 | 175 | } /* decContextSaveStatus */ |
michael@0 | 176 | |
michael@0 | 177 | /* ------------------------------------------------------------------ */ |
michael@0 | 178 | /* decContextSetRounding -- set current rounding mode */ |
michael@0 | 179 | /* */ |
michael@0 | 180 | /* context is the context structure to be updated */ |
michael@0 | 181 | /* newround is the value which will replace the current mode */ |
michael@0 | 182 | /* returns context */ |
michael@0 | 183 | /* */ |
michael@0 | 184 | /* No error is possible. */ |
michael@0 | 185 | /* ------------------------------------------------------------------ */ |
michael@0 | 186 | U_CAPI decContext * U_EXPORT2 uprv_decContextSetRounding(decContext *context, |
michael@0 | 187 | enum rounding newround) { |
michael@0 | 188 | context->round=newround; |
michael@0 | 189 | return context; |
michael@0 | 190 | } /* decContextSetRounding */ |
michael@0 | 191 | |
michael@0 | 192 | /* ------------------------------------------------------------------ */ |
michael@0 | 193 | /* decContextSetStatus -- set status and raise trap if appropriate */ |
michael@0 | 194 | /* */ |
michael@0 | 195 | /* context is the context structure to be updated */ |
michael@0 | 196 | /* status is the DEC_ exception code */ |
michael@0 | 197 | /* returns the context structure */ |
michael@0 | 198 | /* */ |
michael@0 | 199 | /* Control may never return from this routine, if there is a signal */ |
michael@0 | 200 | /* handler and it takes a long jump. */ |
michael@0 | 201 | /* ------------------------------------------------------------------ */ |
michael@0 | 202 | U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatus(decContext *context, uInt status) { |
michael@0 | 203 | context->status|=status; |
michael@0 | 204 | #if 0 /* ICU: Do not raise signals. */ |
michael@0 | 205 | if (status & context->traps) raise(SIGFPE); |
michael@0 | 206 | #endif |
michael@0 | 207 | return context;} /* decContextSetStatus */ |
michael@0 | 208 | |
michael@0 | 209 | /* ------------------------------------------------------------------ */ |
michael@0 | 210 | /* decContextSetStatusFromString -- set status from a string + trap */ |
michael@0 | 211 | /* */ |
michael@0 | 212 | /* context is the context structure to be updated */ |
michael@0 | 213 | /* string is a string exactly equal to one that might be returned */ |
michael@0 | 214 | /* by decContextStatusToString */ |
michael@0 | 215 | /* */ |
michael@0 | 216 | /* The status bit corresponding to the string is set, and a trap */ |
michael@0 | 217 | /* is raised if appropriate. */ |
michael@0 | 218 | /* */ |
michael@0 | 219 | /* returns the context structure, unless the string is equal to */ |
michael@0 | 220 | /* DEC_Condition_MU or is not recognized. In these cases NULL is */ |
michael@0 | 221 | /* returned. */ |
michael@0 | 222 | /* ------------------------------------------------------------------ */ |
michael@0 | 223 | U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusFromString(decContext *context, |
michael@0 | 224 | const char *string) { |
michael@0 | 225 | if (strcmp(string, DEC_Condition_CS)==0) |
michael@0 | 226 | return uprv_decContextSetStatus(context, DEC_Conversion_syntax); |
michael@0 | 227 | if (strcmp(string, DEC_Condition_DZ)==0) |
michael@0 | 228 | return uprv_decContextSetStatus(context, DEC_Division_by_zero); |
michael@0 | 229 | if (strcmp(string, DEC_Condition_DI)==0) |
michael@0 | 230 | return uprv_decContextSetStatus(context, DEC_Division_impossible); |
michael@0 | 231 | if (strcmp(string, DEC_Condition_DU)==0) |
michael@0 | 232 | return uprv_decContextSetStatus(context, DEC_Division_undefined); |
michael@0 | 233 | if (strcmp(string, DEC_Condition_IE)==0) |
michael@0 | 234 | return uprv_decContextSetStatus(context, DEC_Inexact); |
michael@0 | 235 | if (strcmp(string, DEC_Condition_IS)==0) |
michael@0 | 236 | return uprv_decContextSetStatus(context, DEC_Insufficient_storage); |
michael@0 | 237 | if (strcmp(string, DEC_Condition_IC)==0) |
michael@0 | 238 | return uprv_decContextSetStatus(context, DEC_Invalid_context); |
michael@0 | 239 | if (strcmp(string, DEC_Condition_IO)==0) |
michael@0 | 240 | return uprv_decContextSetStatus(context, DEC_Invalid_operation); |
michael@0 | 241 | #if DECSUBSET |
michael@0 | 242 | if (strcmp(string, DEC_Condition_LD)==0) |
michael@0 | 243 | return uprv_decContextSetStatus(context, DEC_Lost_digits); |
michael@0 | 244 | #endif |
michael@0 | 245 | if (strcmp(string, DEC_Condition_OV)==0) |
michael@0 | 246 | return uprv_decContextSetStatus(context, DEC_Overflow); |
michael@0 | 247 | if (strcmp(string, DEC_Condition_PA)==0) |
michael@0 | 248 | return uprv_decContextSetStatus(context, DEC_Clamped); |
michael@0 | 249 | if (strcmp(string, DEC_Condition_RO)==0) |
michael@0 | 250 | return uprv_decContextSetStatus(context, DEC_Rounded); |
michael@0 | 251 | if (strcmp(string, DEC_Condition_SU)==0) |
michael@0 | 252 | return uprv_decContextSetStatus(context, DEC_Subnormal); |
michael@0 | 253 | if (strcmp(string, DEC_Condition_UN)==0) |
michael@0 | 254 | return uprv_decContextSetStatus(context, DEC_Underflow); |
michael@0 | 255 | if (strcmp(string, DEC_Condition_ZE)==0) |
michael@0 | 256 | return context; |
michael@0 | 257 | return NULL; /* Multiple status, or unknown */ |
michael@0 | 258 | } /* decContextSetStatusFromString */ |
michael@0 | 259 | |
michael@0 | 260 | /* ------------------------------------------------------------------ */ |
michael@0 | 261 | /* decContextSetStatusFromStringQuiet -- set status from a string */ |
michael@0 | 262 | /* */ |
michael@0 | 263 | /* context is the context structure to be updated */ |
michael@0 | 264 | /* string is a string exactly equal to one that might be returned */ |
michael@0 | 265 | /* by decContextStatusToString */ |
michael@0 | 266 | /* */ |
michael@0 | 267 | /* The status bit corresponding to the string is set; no trap is */ |
michael@0 | 268 | /* raised. */ |
michael@0 | 269 | /* */ |
michael@0 | 270 | /* returns the context structure, unless the string is equal to */ |
michael@0 | 271 | /* DEC_Condition_MU or is not recognized. In these cases NULL is */ |
michael@0 | 272 | /* returned. */ |
michael@0 | 273 | /* ------------------------------------------------------------------ */ |
michael@0 | 274 | U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusFromStringQuiet(decContext *context, |
michael@0 | 275 | const char *string) { |
michael@0 | 276 | if (strcmp(string, DEC_Condition_CS)==0) |
michael@0 | 277 | return uprv_decContextSetStatusQuiet(context, DEC_Conversion_syntax); |
michael@0 | 278 | if (strcmp(string, DEC_Condition_DZ)==0) |
michael@0 | 279 | return uprv_decContextSetStatusQuiet(context, DEC_Division_by_zero); |
michael@0 | 280 | if (strcmp(string, DEC_Condition_DI)==0) |
michael@0 | 281 | return uprv_decContextSetStatusQuiet(context, DEC_Division_impossible); |
michael@0 | 282 | if (strcmp(string, DEC_Condition_DU)==0) |
michael@0 | 283 | return uprv_decContextSetStatusQuiet(context, DEC_Division_undefined); |
michael@0 | 284 | if (strcmp(string, DEC_Condition_IE)==0) |
michael@0 | 285 | return uprv_decContextSetStatusQuiet(context, DEC_Inexact); |
michael@0 | 286 | if (strcmp(string, DEC_Condition_IS)==0) |
michael@0 | 287 | return uprv_decContextSetStatusQuiet(context, DEC_Insufficient_storage); |
michael@0 | 288 | if (strcmp(string, DEC_Condition_IC)==0) |
michael@0 | 289 | return uprv_decContextSetStatusQuiet(context, DEC_Invalid_context); |
michael@0 | 290 | if (strcmp(string, DEC_Condition_IO)==0) |
michael@0 | 291 | return uprv_decContextSetStatusQuiet(context, DEC_Invalid_operation); |
michael@0 | 292 | #if DECSUBSET |
michael@0 | 293 | if (strcmp(string, DEC_Condition_LD)==0) |
michael@0 | 294 | return uprv_decContextSetStatusQuiet(context, DEC_Lost_digits); |
michael@0 | 295 | #endif |
michael@0 | 296 | if (strcmp(string, DEC_Condition_OV)==0) |
michael@0 | 297 | return uprv_decContextSetStatusQuiet(context, DEC_Overflow); |
michael@0 | 298 | if (strcmp(string, DEC_Condition_PA)==0) |
michael@0 | 299 | return uprv_decContextSetStatusQuiet(context, DEC_Clamped); |
michael@0 | 300 | if (strcmp(string, DEC_Condition_RO)==0) |
michael@0 | 301 | return uprv_decContextSetStatusQuiet(context, DEC_Rounded); |
michael@0 | 302 | if (strcmp(string, DEC_Condition_SU)==0) |
michael@0 | 303 | return uprv_decContextSetStatusQuiet(context, DEC_Subnormal); |
michael@0 | 304 | if (strcmp(string, DEC_Condition_UN)==0) |
michael@0 | 305 | return uprv_decContextSetStatusQuiet(context, DEC_Underflow); |
michael@0 | 306 | if (strcmp(string, DEC_Condition_ZE)==0) |
michael@0 | 307 | return context; |
michael@0 | 308 | return NULL; /* Multiple status, or unknown */ |
michael@0 | 309 | } /* decContextSetStatusFromStringQuiet */ |
michael@0 | 310 | |
michael@0 | 311 | /* ------------------------------------------------------------------ */ |
michael@0 | 312 | /* decContextSetStatusQuiet -- set status without trap */ |
michael@0 | 313 | /* */ |
michael@0 | 314 | /* context is the context structure to be updated */ |
michael@0 | 315 | /* status is the DEC_ exception code */ |
michael@0 | 316 | /* returns the context structure */ |
michael@0 | 317 | /* */ |
michael@0 | 318 | /* No error is possible. */ |
michael@0 | 319 | /* ------------------------------------------------------------------ */ |
michael@0 | 320 | U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusQuiet(decContext *context, uInt status) { |
michael@0 | 321 | context->status|=status; |
michael@0 | 322 | return context;} /* decContextSetStatusQuiet */ |
michael@0 | 323 | |
michael@0 | 324 | /* ------------------------------------------------------------------ */ |
michael@0 | 325 | /* decContextStatusToString -- convert status flags to a string */ |
michael@0 | 326 | /* */ |
michael@0 | 327 | /* context is a context with valid status field */ |
michael@0 | 328 | /* */ |
michael@0 | 329 | /* returns a constant string describing the condition. If multiple */ |
michael@0 | 330 | /* (or no) flags are set, a generic constant message is returned. */ |
michael@0 | 331 | /* ------------------------------------------------------------------ */ |
michael@0 | 332 | U_CAPI const char * U_EXPORT2 uprv_decContextStatusToString(const decContext *context) { |
michael@0 | 333 | Int status=context->status; |
michael@0 | 334 | |
michael@0 | 335 | /* test the five IEEE first, as some of the others are ambiguous when */ |
michael@0 | 336 | /* DECEXTFLAG=0 */ |
michael@0 | 337 | if (status==DEC_Invalid_operation ) return DEC_Condition_IO; |
michael@0 | 338 | if (status==DEC_Division_by_zero ) return DEC_Condition_DZ; |
michael@0 | 339 | if (status==DEC_Overflow ) return DEC_Condition_OV; |
michael@0 | 340 | if (status==DEC_Underflow ) return DEC_Condition_UN; |
michael@0 | 341 | if (status==DEC_Inexact ) return DEC_Condition_IE; |
michael@0 | 342 | |
michael@0 | 343 | if (status==DEC_Division_impossible ) return DEC_Condition_DI; |
michael@0 | 344 | if (status==DEC_Division_undefined ) return DEC_Condition_DU; |
michael@0 | 345 | if (status==DEC_Rounded ) return DEC_Condition_RO; |
michael@0 | 346 | if (status==DEC_Clamped ) return DEC_Condition_PA; |
michael@0 | 347 | if (status==DEC_Subnormal ) return DEC_Condition_SU; |
michael@0 | 348 | if (status==DEC_Conversion_syntax ) return DEC_Condition_CS; |
michael@0 | 349 | if (status==DEC_Insufficient_storage ) return DEC_Condition_IS; |
michael@0 | 350 | if (status==DEC_Invalid_context ) return DEC_Condition_IC; |
michael@0 | 351 | #if DECSUBSET |
michael@0 | 352 | if (status==DEC_Lost_digits ) return DEC_Condition_LD; |
michael@0 | 353 | #endif |
michael@0 | 354 | if (status==0 ) return DEC_Condition_ZE; |
michael@0 | 355 | return DEC_Condition_MU; /* Multiple errors */ |
michael@0 | 356 | } /* decContextStatusToString */ |
michael@0 | 357 | |
michael@0 | 358 | /* ------------------------------------------------------------------ */ |
michael@0 | 359 | /* decContextTestEndian -- test whether DECLITEND is set correctly */ |
michael@0 | 360 | /* */ |
michael@0 | 361 | /* quiet is 1 to suppress message; 0 otherwise */ |
michael@0 | 362 | /* returns 0 if DECLITEND is correct */ |
michael@0 | 363 | /* 1 if DECLITEND is incorrect and should be 1 */ |
michael@0 | 364 | /* -1 if DECLITEND is incorrect and should be 0 */ |
michael@0 | 365 | /* */ |
michael@0 | 366 | /* A message is displayed if the return value is not 0 and quiet==0. */ |
michael@0 | 367 | /* */ |
michael@0 | 368 | /* No error is possible. */ |
michael@0 | 369 | /* ------------------------------------------------------------------ */ |
michael@0 | 370 | #if 0 /* ICU: Unused function. Anyway, do not call printf(). */ |
michael@0 | 371 | U_CAPI Int U_EXPORT2 uprv_decContextTestEndian(Flag quiet) { |
michael@0 | 372 | Int res=0; /* optimist */ |
michael@0 | 373 | uInt dle=(uInt)DECLITEND; /* unsign */ |
michael@0 | 374 | if (dle>1) dle=1; /* ensure 0 or 1 */ |
michael@0 | 375 | |
michael@0 | 376 | if (LITEND!=DECLITEND) { |
michael@0 | 377 | const char *adj; |
michael@0 | 378 | if (!quiet) { |
michael@0 | 379 | if (LITEND) adj="little"; |
michael@0 | 380 | else adj="big"; |
michael@0 | 381 | printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n", |
michael@0 | 382 | DECLITEND, adj); |
michael@0 | 383 | } |
michael@0 | 384 | res=(Int)LITEND-dle; |
michael@0 | 385 | } |
michael@0 | 386 | return res; |
michael@0 | 387 | } /* decContextTestEndian */ |
michael@0 | 388 | #endif |
michael@0 | 389 | |
michael@0 | 390 | /* ------------------------------------------------------------------ */ |
michael@0 | 391 | /* decContextTestSavedStatus -- test bits in saved status */ |
michael@0 | 392 | /* */ |
michael@0 | 393 | /* oldstatus is the status word to be tested */ |
michael@0 | 394 | /* mask indicates the bits to be tested (the oldstatus bits that */ |
michael@0 | 395 | /* correspond to each 1 bit in the mask are tested) */ |
michael@0 | 396 | /* returns 1 if any of the tested bits are 1, or 0 otherwise */ |
michael@0 | 397 | /* */ |
michael@0 | 398 | /* No error is possible. */ |
michael@0 | 399 | /* ------------------------------------------------------------------ */ |
michael@0 | 400 | U_CAPI uInt U_EXPORT2 uprv_decContextTestSavedStatus(uInt oldstatus, uInt mask) { |
michael@0 | 401 | return (oldstatus&mask)!=0; |
michael@0 | 402 | } /* decContextTestSavedStatus */ |
michael@0 | 403 | |
michael@0 | 404 | /* ------------------------------------------------------------------ */ |
michael@0 | 405 | /* decContextTestStatus -- test bits in current status */ |
michael@0 | 406 | /* */ |
michael@0 | 407 | /* context is the context structure to be updated */ |
michael@0 | 408 | /* mask indicates the bits to be tested (the status bits that */ |
michael@0 | 409 | /* correspond to each 1 bit in the mask are tested) */ |
michael@0 | 410 | /* returns 1 if any of the tested bits are 1, or 0 otherwise */ |
michael@0 | 411 | /* */ |
michael@0 | 412 | /* No error is possible. */ |
michael@0 | 413 | /* ------------------------------------------------------------------ */ |
michael@0 | 414 | U_CAPI uInt U_EXPORT2 uprv_decContextTestStatus(decContext *context, uInt mask) { |
michael@0 | 415 | return (context->status&mask)!=0; |
michael@0 | 416 | } /* decContextTestStatus */ |
michael@0 | 417 | |
michael@0 | 418 | /* ------------------------------------------------------------------ */ |
michael@0 | 419 | /* decContextZeroStatus -- clear all status bits */ |
michael@0 | 420 | /* */ |
michael@0 | 421 | /* context is the context structure to be updated */ |
michael@0 | 422 | /* returns context */ |
michael@0 | 423 | /* */ |
michael@0 | 424 | /* No error is possible. */ |
michael@0 | 425 | /* ------------------------------------------------------------------ */ |
michael@0 | 426 | U_CAPI decContext * U_EXPORT2 uprv_decContextZeroStatus(decContext *context) { |
michael@0 | 427 | context->status=0; |
michael@0 | 428 | return context; |
michael@0 | 429 | } /* decContextZeroStatus */ |
michael@0 | 430 |