------------------------------------------------------------------ */ decNumberLn -- natural logarithm */ / This computes C = ln(A) */ / res is C, the result. C may be A */ rhs is A */ set is the context; note that rounding mode has no e
| 1254 | /* to calculate at p+e+2). */ |
| 1255 | /* ------------------------------------------------------------------ */ |
| 1256 | decNumber * decNumberLn(decNumber *res, const decNumber *rhs, |
| 1257 | decContext *set) { |
| 1258 | uInt status=0; // accumulator |
| 1259 | #if DECSUBSET |
| 1260 | decNumber *allocrhs=NULL; // non-NULL if rounded rhs allocated |
| 1261 | #endif |
| 1262 | |
| 1263 | #if DECCHECK |
| 1264 | if (decCheckOperands(res, DECUNUSED, rhs, set)) return res; |
| 1265 | #endif |
| 1266 | |
| 1267 | // Check restrictions; this is a math function; if not violated |
| 1268 | // then carry out the operation. |
| 1269 | if (!decCheckMath(rhs, set, &status)) do { // protect allocation |
| 1270 | #if DECSUBSET |
| 1271 | if (!set->extended) { |
| 1272 | // reduce operand and set lostDigits status, as needed |
| 1273 | if (rhs->digits>set->digits) { |
| 1274 | allocrhs=decRoundOperand(rhs, set, &status); |
| 1275 | if (allocrhs==NULL) break; |
| 1276 | rhs=allocrhs; |
| 1277 | } |
| 1278 | // special check in subset for rhs=0 |
| 1279 | if (ISZERO(rhs)) { // +/- zeros -> error |
| 1280 | status|=DEC_Invalid_operation; |
| 1281 | break;} |
| 1282 | } // extended=0 |
| 1283 | #endif |
| 1284 | decLnOp(res, rhs, set, &status); |
| 1285 | } while(0); // end protected |
| 1286 | |
| 1287 | #if DECSUBSET |
| 1288 | if (allocrhs !=NULL) free(allocrhs); // drop any storage used |
| 1289 | #endif |
| 1290 | // apply significant status |
| 1291 | if (status!=0) decStatus(res, status, set); |
| 1292 | #if DECCHECK |
| 1293 | decCheckInexact(res, set); |
| 1294 | #endif |
| 1295 | return res; |
| 1296 | } // decNumberLn |
| 1297 | |
| 1298 | /* ------------------------------------------------------------------ */ |
| 1299 | /* decNumberLogB - get adjusted exponent, by 754 rules */ |
no test coverage detected