------------------------------------------------------------------ */ decNaNs -- handle NaN operand or operands */ / res is the result number */ lhs is the first operand */ rhs is the second operand, or NULL if none */ context is used to limit payload length
| 7686 | /* to a qNaN and Invalid operation is set. */ |
| 7687 | /* ------------------------------------------------------------------ */ |
| 7688 | static decNumber * decNaNs(decNumber *res, const decNumber *lhs, |
| 7689 | const decNumber *rhs, decContext *set, |
| 7690 | uInt *status) { |
| 7691 | // This decision tree ends up with LHS being the source pointer, |
| 7692 | // and status updated if need be |
| 7693 | if (lhs->bits & DECSNAN) |
| 7694 | *status|=DEC_Invalid_operation | DEC_sNaN; |
| 7695 | else if (rhs==NULL); |
| 7696 | else if (rhs->bits & DECSNAN) { |
| 7697 | lhs=rhs; |
| 7698 | *status|=DEC_Invalid_operation | DEC_sNaN; |
| 7699 | } |
| 7700 | else if (lhs->bits & DECNAN); |
| 7701 | else lhs=rhs; |
| 7702 | |
| 7703 | // propagate the payload |
| 7704 | if (lhs->digits<=set->digits) decNumberCopy(res, lhs); // easy |
| 7705 | else { // too long |
| 7706 | const Unit *ul; |
| 7707 | Unit *ur, *uresp1; |
| 7708 | // copy safe number of units, then decapitate |
| 7709 | res->bits=lhs->bits; // need sign etc. |
| 7710 | uresp1=res->lsu+D2U(set->digits); |
| 7711 | for (ur=res->lsu, ul=lhs->lsu; ur<uresp1; ur++, ul++) *ur=*ul; |
| 7712 | res->digits=D2U(set->digits)*DECDPUN; |
| 7713 | // maybe still too long |
| 7714 | if (res->digits>set->digits) decDecap(res, res->digits-set->digits); |
| 7715 | } |
| 7716 | |
| 7717 | res->bits&=~DECSNAN; // convert any sNaN to NaN, while |
| 7718 | res->bits|=DECNAN; // .. preserving sign |
| 7719 | res->exponent=0; // clean exponent |
| 7720 | // [coefficient was copied/decapitated] |
| 7721 | return res; |
| 7722 | } // decNaNs |
| 7723 | |
| 7724 | /* ------------------------------------------------------------------ */ |
| 7725 | /* decStatus -- apply non-zero status */ |
no test coverage detected