------------------------------------------------------------------ */ decSetOverflow -- set number to proper overflow value */ / dn is the number (used for sign [only] and result) */ set is the context [used for the rounding mode, etc.] */ status contains the current status to be updated */ / This sets the sign of a number and sets its value to
| 7344 | /* dn and the rounding mode, following IEEE 754 rules. */ |
| 7345 | /* ------------------------------------------------------------------ */ |
| 7346 | static void decSetOverflow(decNumber *dn, decContext *set, uInt *status) { |
| 7347 | Flag needmax=0; // result is maximum finite value |
| 7348 | uByte sign=dn->bits&DECNEG; // clean and save sign bit |
| 7349 | |
| 7350 | if (ISZERO(dn)) { // zero does not overflow magnitude |
| 7351 | Int emax=set->emax; // limit value |
| 7352 | if (set->clamp) emax-=set->digits-1; // lower if clamping |
| 7353 | if (dn->exponent>emax) { // clamp required |
| 7354 | dn->exponent=emax; |
| 7355 | *status|=DEC_Clamped; |
| 7356 | } |
| 7357 | return; |
| 7358 | } |
| 7359 | |
| 7360 | decNumberZero(dn); |
| 7361 | switch (set->round) { |
| 7362 | case DEC_ROUND_DOWN: { |
| 7363 | needmax=1; // never Infinity |
| 7364 | break;} // r-d |
| 7365 | case DEC_ROUND_05UP: { |
| 7366 | needmax=1; // never Infinity |
| 7367 | break;} // r-05 |
| 7368 | case DEC_ROUND_CEILING: { |
| 7369 | if (sign) needmax=1; // Infinity if non-negative |
| 7370 | break;} // r-c |
| 7371 | case DEC_ROUND_FLOOR: { |
| 7372 | if (!sign) needmax=1; // Infinity if negative |
| 7373 | break;} // r-f |
| 7374 | default: break; // Infinity in all other cases |
| 7375 | } |
| 7376 | if (needmax) { |
| 7377 | decSetMaxValue(dn, set); |
| 7378 | dn->bits=sign; // set sign |
| 7379 | } |
| 7380 | else dn->bits=sign|DECINF; // Value is +/-Infinity |
| 7381 | *status|=DEC_Overflow | DEC_Inexact | DEC_Rounded; |
| 7382 | } // decSetOverflow |
| 7383 | |
| 7384 | /* ------------------------------------------------------------------ */ |
| 7385 | /* decSetMaxValue -- set number to +Nmax (maximum normal value) */ |
no test coverage detected