------------------------------------------------------------------ */ decRoundOperand -- round an operand [used for subset only] */ / dn is the number to round (dn->digits is > set->digits) */ set is the relevant context */ status is the status accumulator */ / returns an allocated decNumber with the rounded resu
| 6803 | /* is returned. */ |
| 6804 | /* ------------------------------------------------------------------ */ |
| 6805 | static decNumber *decRoundOperand(const decNumber *dn, decContext *set, |
| 6806 | uInt *status) { |
| 6807 | decNumber *res; // result structure |
| 6808 | uInt newstatus=0; // status from round |
| 6809 | Int residue=0; // rounding accumulator |
| 6810 | |
| 6811 | // Allocate storage for the returned decNumber, big enough for the |
| 6812 | // length specified by the context |
| 6813 | res=(decNumber *)malloc(sizeof(decNumber) |
| 6814 | +(D2U(set->digits)-1)*sizeof(Unit)); |
| 6815 | if (res==NULL) { |
| 6816 | *status|=DEC_Insufficient_storage; |
| 6817 | return NULL; |
| 6818 | } |
| 6819 | decCopyFit(res, dn, set, &residue, &newstatus); |
| 6820 | decApplyRound(res, set, residue, &newstatus); |
| 6821 | |
| 6822 | // If that set Inexact then "lost digits" is raised... |
| 6823 | if (newstatus & DEC_Inexact) newstatus|=DEC_Lost_digits; |
| 6824 | *status|=newstatus; |
| 6825 | return res; |
| 6826 | } // decRoundOperand |
| 6827 | #endif |
| 6828 | |
| 6829 | /* ------------------------------------------------------------------ */ |
no test coverage detected