------------------------------------------------------------------ */ decFloatReduce -- reduce finite coefficient to minimum length */ / result gets the reduced decFloat */ df is the source decFloat */ set is the context */ returns result, which will be canonical
| 3187 | /* Reduced zero has an exponent q=0. */ |
| 3188 | /* ------------------------------------------------------------------ */ |
| 3189 | decFloat * decFloatReduce(decFloat *result, const decFloat *df, |
| 3190 | decContext *set) { |
| 3191 | bcdnum num; // work |
| 3192 | uByte buf[DECPMAX], *ub; // coefficient and pointer |
| 3193 | if (df!=result) *result=*df; // copy, if needed |
| 3194 | if (DFISNAN(df)) return decNaNs(result, df, NULL, set); // sNaN |
| 3195 | // zeros and infinites propagate too |
| 3196 | if (DFISINF(df)) return decInfinity(result, df); // canonical |
| 3197 | if (DFISZERO(df)) { |
| 3198 | uInt sign=DFWORD(df, 0)&DECFLOAT_Sign; |
| 3199 | decFloatZero(result); |
| 3200 | DFWORD(result, 0)|=sign; |
| 3201 | return result; // exponent dropped, sign OK |
| 3202 | } |
| 3203 | // non-zero finite |
| 3204 | GETCOEFF(df, buf); |
| 3205 | ub=buf+DECPMAX-1; // -> lsd |
| 3206 | if (*ub) return result; // no trailing zeros |
| 3207 | for (ub--; *ub==0;) ub--; // terminates because non-zero |
| 3208 | // *ub is the first non-zero from the right |
| 3209 | num.sign=DFWORD(df, 0)&DECFLOAT_Sign; // set up number... |
| 3210 | num.exponent=GETEXPUN(df)+(Int)(buf+DECPMAX-1-ub); // adjusted exponent |
| 3211 | num.msd=buf; |
| 3212 | num.lsd=ub; |
| 3213 | return decFinalize(result, &num, set); |
| 3214 | } // decFloatReduce |
| 3215 | |
| 3216 | /* ------------------------------------------------------------------ */ |
| 3217 | /* decFloatRemainder -- integer divide and return remainder */ |
nothing calls this directly
no test coverage detected