Lines Matching refs:rhs

169 /*	rhs -- right hand side (operand, of an operation)	      */
237 static Int decCompare(const decNumber *lhs, const decNumber *rhs, Flag);
286 #define SPECIALARG (rhs->bits & DECSPECIAL)
287 #define SPECIALARGS ((lhs->bits | rhs->bits) & DECSPECIAL)
729 /* rhs is A */
738 decNumber * decNumberAbs(decNumber *res, const decNumber *rhs,
744 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
748 dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
749 decAddOp(res, &dzero, rhs, set, (uByte)(rhs->bits & DECNEG), &status);
764 /* rhs is B */
771 const decNumber *rhs, decContext *set) {
773 decAddOp(res, lhs, rhs, set, 0, &status);
788 /* rhs is B */
797 const decNumber *rhs, decContext *set) {
803 if (decCheckOperands(res, lhs, rhs, set)) return res;
807 || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
814 ub=rhs->lsu; /* .. */
817 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
859 /* rhs is B */
865 const decNumber *rhs, decContext *set) {
867 decCompareOp(res, lhs, rhs, set, COMPARE, &status);
879 /* rhs is B */
885 const decNumber *rhs, decContext *set) {
887 decCompareOp(res, lhs, rhs, set, COMPSIG, &status);
899 /* rhs is B */
906 const decNumber *rhs, decContext *set) {
908 decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
920 /* rhs is B */
927 const decNumber *rhs, decContext *set) {
937 if (decCheckOperands(res, lhs, rhs, set)) return res;
956 if (decNumberIsNegative(rhs)) { /* rhs<0 */
958 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
966 decNumberCopy(b, rhs); /* copy content */
968 rhs=b; /* use copy from here on */
970 decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
986 /* rhs is B */
992 const decNumber *rhs, decContext *set) {
994 decDivideOp(res, lhs, rhs, set, DIVIDE, &status);
1009 /* rhs is B */
1015 const decNumber *rhs, decContext *set) {
1017 decDivideOp(res, lhs, rhs, set, DIVIDEINT, &status);
1028 /* rhs is A */
1047 decNumber * decNumberExp(decNumber *res, const decNumber *rhs,
1051 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1055 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1062 if (!decCheckMath(rhs, set, &status)) do { /* protect allocation */
1066 if (rhs->digits>set->digits) {
1067 allocrhs=decRoundOperand(rhs, set, &status);
1069 rhs=allocrhs;
1073 decExpOp(res, rhs, set, &status);
1094 /* rhs is B */
1104 const decNumber *rhs, const decNumber *fhs,
1115 if (decCheckOperands(res, lhs, rhs, set)) return res;
1127 || (!decNumberIsSpecial(rhs) && decCheckMath(rhs, set, &status))
1131 dcmul.digits=lhs->digits+rhs->digits; /* just enough */
1147 decMultiplyOp(acc, lhs, rhs, &dcmul, &status);
1186 /* rhs is A */
1194 decNumber * decNumberInvert(decNumber *res, const decNumber *rhs,
1200 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1203 if (rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
1208 ua=rhs->lsu; /* bottom-up */
1210 msua=ua+D2U(rhs->digits)-1; /* -> msu of rhs */
1219 /* always need to examine all bits in rhs */
1245 /* rhs is A */
1267 decNumber * decNumberLn(decNumber *res, const decNumber *rhs,
1271 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1275 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1280 if (!decCheckMath(rhs, set, &status)) do { /* protect allocation */
1284 if (rhs->digits>set->digits) {
1285 allocrhs=decRoundOperand(rhs, set, &status);
1287 rhs=allocrhs;
1289 /* special check in subset for rhs=0 */
1290 if (ISZERO(rhs)) { /* +/- zeros -> error */
1295 decLnOp(res, rhs, set, &status);
1315 /* rhs is A */
1333 decNumber * decNumberLogB(decNumber *res, const decNumber *rhs,
1338 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1342 if (decNumberIsNaN(rhs)) decNaNs(res, rhs, NULL, set, &status);
1343 else if (decNumberIsInfinite(rhs)) decNumberCopyAbs(res, rhs);
1344 else if (decNumberIsZero(rhs)) {
1350 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
1364 /* rhs is A */
1383 /* ln(A) this is the max(p, rhs->digits + t) + 3, where p is the */
1389 decNumber * decNumberLog10(decNumber *res, const decNumber *rhs,
1407 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1413 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1418 if (!decCheckMath(rhs, set, &status)) do { /* protect malloc */
1422 if (rhs->digits>set->digits) {
1423 allocrhs=decRoundOperand(rhs, set, &status);
1425 rhs=allocrhs;
1427 /* special check in subset for rhs=0 */
1428 if (ISZERO(rhs)) { /* +/- zeros -> error */
1437 if (!(rhs->bits&(DECNEG|DECSPECIAL)) && !ISZERO(rhs)) {
1443 decCopyFit(w, rhs, &aset, &residue, &copystat); /* copy & shorten */
1444 /* if exact and the digit is 1, rhs is a power of 10 */
1465 p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
1478 decLnOp(a, rhs, &aset, &status); /* a=ln(rhs) */
1532 /* rhs is B */
1538 const decNumber *rhs, decContext *set) {
1540 decCompareOp(res, lhs, rhs, set, COMPMAX, &status);
1555 /* rhs is B */
1561 const decNumber *rhs, decContext *set) {
1563 decCompareOp(res, lhs, rhs, set, COMPMAXMAG, &status);
1578 /* rhs is B */
1584 const decNumber *rhs, decContext *set) {
1586 decCompareOp(res, lhs, rhs, set, COMPMIN, &status);
1601 /* rhs is B */
1607 const decNumber *rhs, decContext *set) {
1609 decCompareOp(res, lhs, rhs, set, COMPMINMAG, &status);
1623 /* rhs is A */
1631 decNumber * decNumberMinus(decNumber *res, const decNumber *rhs,
1637 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1641 dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
1642 decAddOp(res, &dzero, rhs, set, DECNEG, &status);
1656 /* rhs is A */
1661 decNumber * decNumberNextMinus(decNumber *res, const decNumber *rhs,
1667 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1671 if ((rhs->bits&(DECINF|DECNEG))==DECINF) {
1680 decAddOp(res, rhs, &dtiny, &workset, DECNEG, &status);
1692 /* rhs is A */
1697 decNumber * decNumberNextPlus(decNumber *res, const decNumber *rhs,
1703 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1707 if ((rhs->bits&(DECINF|DECNEG))==(DECINF|DECNEG)) {
1717 decAddOp(res, rhs, &dtiny, &workset, 0, &status);
1724 /* decNumberNextToward -- next towards rhs */
1732 /* rhs is B */
1738 const decNumber *rhs, decContext *set) {
1744 if (decCheckOperands(res, lhs, rhs, set)) return res;
1747 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) {
1748 decNaNs(res, lhs, rhs, set, &status);
1751 result=decCompare(lhs, rhs, 0); /* sign matters */
1754 if (result==0) decNumberCopySign(res, lhs, rhs); /* easy */
1757 if (result<0) { /* lhs<rhs, do nextplus */
1767 else { /* lhs>rhs, do nextminus */
1797 /* rhs is B */
1806 const decNumber *rhs, decContext *set) {
1812 if (decCheckOperands(res, lhs, rhs, set)) return res;
1816 || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
1822 ub=rhs->lsu; /* .. */
1825 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
1865 /* rhs is A */
1875 decNumber * decNumberPlus(decNumber *res, const decNumber *rhs,
1880 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
1884 dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
1885 decAddOp(res, &dzero, rhs, set, 0, &status);
1900 /* rhs is B */
1906 const decNumber *rhs, decContext *set) {
1908 decMultiplyOp(res, lhs, rhs, set, &status);
1923 /* rhs is B */
1943 const decNumber *rhs, decContext *set) {
1946 decNumber *allocrhs=NULL; /* .., rhs */
1951 Int n; /* rhs in binary */
1952 Flag rhsint=0; /* 1 if rhs is an integer */
1954 Flag isoddint=0; /* 1 if rhs is an integer and odd */
1973 if (decCheckOperands(res, lhs, rhs, set)) return res;
1984 if (rhs->digits>reqdigits) {
1985 allocrhs=decRoundOperand(rhs, set, &status);
1987 rhs=allocrhs;
1993 /* handle NaNs and rhs Infinity (lhs infinity is harder) */
1995 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) { /* NaNs */
1996 decNaNs(res, lhs, rhs, set, &status);
1998 if (decNumberIsInfinite(rhs)) { /* rhs Infinity */
1999 Flag rhsneg=rhs->bits&DECNEG; /* save rhs sign */
2027 /* Original rhs may be an integer that fits and is in range */
2028 n=decGetInt(rhs);
2041 uByte rbits=rhs->bits; /* save */
2067 uByte rbits=rhs->bits; /* save */
2082 /* here both lhs and rhs are finite; rhs==0 is handled in the */
2084 if (!useint) { /* non-integral rhs */
2091 || decCheckMath(rhs, set, &status)) break; /* variable status */
2098 /* calculate the result using exp(ln(lhs)*rhs), which can */
2109 } /* non-integer rhs */
2111 else { /* rhs is in-range integer */
2117 /* rhs is a non-zero integer */
2123 aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
2144 if (!useint) { /* non-integral rhs */
2161 decMultiplyOp(dac, dac, rhs, &aset, &status); /* dac=dac*rhs */
2165 } /* non-integer rhs */
2173 if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2222 if (!set->extended && decNumberIsNegative(rhs)) {
2241 decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
2246 } /* rhs integer path */
2279 /* rhs is B, the number with exponent to match */
2288 const decNumber *rhs, decContext *set) {
2290 decQuantizeOp(res, lhs, rhs, set, 1, &status);
2301 /* rhs is A */
2307 decNumber * decNumberNormalize(decNumber *res, const decNumber *rhs,
2309 return decNumberReduce(res, rhs, set);
2312 decNumber * decNumberReduce(decNumber *res, const decNumber *rhs,
2315 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
2322 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
2329 if (rhs->digits>set->digits) {
2330 allocrhs=decRoundOperand(rhs, set, &status);
2332 rhs=allocrhs;
2339 if (decNumberIsNaN(rhs)) {
2340 decNaNs(res, rhs, NULL, set, &status);
2345 decCopyFit(res, rhs, set, &residue, &status); /* copy & round */
2368 /* rhs is B, the requested exponent */
2377 const decNumber *rhs, decContext *set) {
2379 decQuantizeOp(res, lhs, rhs, set, 0, &status);
2391 /* rhs is B */
2397 const decNumber *rhs, decContext *set) {
2399 decDivideOp(res, lhs, rhs, set, REMAINDER, &status);
2414 /* rhs is B */
2420 const decNumber *rhs, decContext *set) {
2422 decDivideOp(res, lhs, rhs, set, REMNEAR, &status);
2438 /* rhs is B, the number of digits to rotate (-ve to right) */
2456 const decNumber *rhs, decContext *set) {
2458 Int rotate; /* rhs as an Int */
2461 if (decCheckOperands(res, lhs, rhs, set)) return res;
2465 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2466 decNaNs(res, lhs, rhs, set, &status);
2467 /* rhs must be an integer */
2468 else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
2470 else { /* both numeric, rhs is an integer */
2471 rotate=decGetInt(rhs); /* [cannot fail] */
2476 else { /* rhs is OK */
2561 } /* rhs OK */
2572 /* rhs is the second (usually a pattern) */
2577 const decNumber *rhs) {
2581 if (decCheckOperands(res, lhs, rhs, DECUNCONT)) return res;
2585 if (decNumberIsNaN(lhs) && decNumberIsNaN(rhs)) ret=1;
2586 else if (decNumberIsInfinite(lhs) && decNumberIsInfinite(rhs)) ret=1;
2589 else if (lhs->exponent==rhs->exponent) ret=1;
2604 /* rhs is B, the requested power of ten to use */
2612 const decNumber *rhs, decContext *set) {
2618 if (decCheckOperands(res, lhs, rhs, set)) return res;
2622 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2623 decNaNs(res, lhs, rhs, set, &status);
2624 /* rhs must be an integer */
2625 else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
2628 /* lhs is a number; rhs is a finite with q==0 */
2629 reqexp=decGetInt(rhs); /* [cannot fail] */
2634 else { /* rhs is OK */
2641 } /* rhs OK */
2642 } /* rhs finite */
2654 /* rhs is B, the number of digits to shift (-ve to right) */
2669 const decNumber *rhs, decContext *set) {
2671 Int shift; /* rhs as an Int */
2674 if (decCheckOperands(res, lhs, rhs, set)) return res;
2678 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2679 decNaNs(res, lhs, rhs, set, &status);
2680 /* rhs must be an integer */
2681 else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
2683 else { /* both numeric, rhs is an integer */
2684 shift=decGetInt(rhs); /* [cannot fail] */
2689 else { /* rhs is OK */
2719 } /* rhs OK */
2731 /* rhs is A */
2797 decNumber * decNumberSquareRoot(decNumber *res, const decNumber *rhs,
2812 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
2831 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
2838 if (rhs->digits>set->digits) {
2839 allocrhs=decRoundOperand(rhs, set, &status);
2843 rhs=allocrhs;
2851 if (decNumberIsInfinite(rhs)) { /* an infinity */
2852 if (decNumberIsNegative(rhs)) status|=DEC_Invalid_operation;
2853 else decNumberCopy(res, rhs); /* +Infinity */
2855 else decNaNs(res, rhs, NULL, set, &status); /* a NaN */
2860 /* [It would be nicer to write: ideal=rhs->exponent>>1, but this */
2862 ideal=(rhs->exponent&~1)/2; /* target */
2865 if (ISZERO(rhs)) {
2866 decNumberCopy(res, rhs); /* could be 0 or -0 */
2874 if (decNumberIsNegative(rhs)) {
2886 workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
2890 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2910 /* copy rhs -> f, save exponent, and reduce so 0.1 <= f < 1 */
2911 decNumberCopy(f, rhs);
3068 decCompareOp(t, b, rhs, &workset, COMPARE, &mstatus); /* b ? rhs */
3100 Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
3134 /* rhs is B */
3140 const decNumber *rhs, decContext *set) {
3143 decAddOp(res, lhs, rhs, set, DECNEG, &status);
3156 /* rhs is input number */
3159 /* res must have space for any value of rhs. */
3163 /* rescale(rhs, 0) if rhs->exponent is <0. */
3164 /* Otherwise the result is rhs (so no error is possible, except for */
3169 /* Inexact if the result differs numerically from rhs; the other */
3172 decNumber * decNumberToIntegralExact(decNumber *res, const decNumber *rhs,
3179 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
3184 if (decNumberIsInfinite(rhs)) decNumberCopy(res, rhs); /* an Infinity */
3185 else decNaNs(res, rhs, NULL, set, &status); /* a NaN */
3189 if (rhs->exponent>=0) return decNumberCopy(res, rhs);
3192 workset.digits=rhs->digits; /* no length rounding */
3195 decNumberQuantize(res, rhs, &dn, &workset);
3202 decNumber * decNumberToIntegralValue(decNumber *res, const decNumber *rhs,
3206 decNumberToIntegralExact(res, rhs, &workset);
3220 /* rhs is B */
3229 const decNumber *rhs, decContext *set) {
3235 if (decCheckOperands(res, lhs, rhs, set)) return res;
3239 || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
3245 ub=rhs->lsu; /* .. */
3248 msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
3380 /* rhs is A */
3386 decNumber * decNumberCopyAbs(decNumber *res, const decNumber *rhs) {
3388 if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
3390 decNumberCopy(res, rhs);
3401 /* rhs is A */
3407 decNumber * decNumberCopyNegate(decNumber *res, const decNumber *rhs) {
3409 if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
3411 decNumberCopy(res, rhs);
3423 /* rhs is B */
3429 const decNumber *rhs) {
3430 uByte sign; /* rhs sign */
3432 if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
3434 sign=rhs->bits & DECNEG; /* save sign bit */
3437 res->bits|=sign; /* set from rhs */
3769 /* rhs is B */
3771 /* negate is DECNEG if rhs should be negated, or 0 otherwise */
3798 const decNumber *rhs, decContext *set,
3802 decNumber *allocrhs=NULL; /* .., rhs */
3819 if (decCheckOperands(res, lhs, rhs, set)) return res;
3831 if (rhs->digits>reqdigits) {
3832 allocrhs=decRoundOperand(rhs, set, status);
3834 rhs=allocrhs;
3841 diffsign=(Flag)((lhs->bits^rhs->bits^negate)&DECNEG);
3846 decNaNs(res, lhs, rhs, set, status);
3850 if (decNumberIsInfinite(rhs) && diffsign) {
3856 else bits=(rhs->bits^negate) & DECNEG;/* RHS must be Infinity */
3870 decCopyFit(res, rhs, set, &residue, status); /* copy (as needed) */
3871 res->bits^=negate; /* flip if rhs was negated */
3901 if (ISZERO(rhs)) { /* [lhs is non-zero] */
3903 Int rexp=rhs->exponent; /* save in case RHS==RES */
3904 bits=rhs->bits; /* be clean */
3931 padding=rhs->exponent-lhs->exponent;
3937 && rhs->digits<=DECDPUN
3938 && rhs->exponent>=set->emin /* [some normals drop through] */
3939 && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
3940 && rhs->digits<=reqdigits
3944 partial+=*rhs->lsu;
3955 partial-=*rhs->lsu;
3967 /* Now align (pad) the lhs or rhs so they can be added or */
3974 rhsshift=0; /* rhs shift to left (padding) in Units */
3987 bits=(uByte)(rhs->bits^negate); /* assumed sign is now that of RHS */
3988 t=lhs; lhs=rhs; rhs=t;
3992 /* If, after pad, rhs would be longer than lhs by digits+1 or */
3995 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
3998 Int shift=reqdigits-rhs->digits; /* left shift needed */
4002 decCopyFit(res, rhs, set, &residue, status);
4008 /* flip the result sign if unswapped and rhs was negated */
4021 maxdigits=rhs->digits+padding; /* virtual length of RHS */
4031 || (res==rhs && rhsshift>0)) { /* destructive overlap */
4051 decDumpAr('B', rhs->lsu, D2U(rhs->digits));
4057 rhs->lsu, D2U(rhs->digits),
4151 /* rhs is B */
4207 /* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/
4212 const decNumber *lhs, const decNumber *rhs,
4216 decNumber *allocrhs=NULL; /* .., rhs */
4256 if (decCheckOperands(res, lhs, rhs, set)) return res;
4268 if (rhs->digits>reqdigits) {
4269 allocrhs=decRoundOperand(rhs, set, status);
4271 rhs=allocrhs;
4277 bits=(lhs->bits^rhs->bits)&DECNEG; /* assumed sign for divisions */
4282 decNaNs(res, lhs, rhs, set, status);
4287 if (decNumberIsInfinite(rhs) || /* two infinities are invalid .. */
4318 /* handle 0 rhs (x/0) */
4319 if (ISZERO(rhs)) { /* x/0 is always exceptional */
4342 exponent=lhs->exponent-rhs->exponent; /* ideal exponent */
4353 exponent=rhs->exponent; /* [save in case overwrite] */
4366 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4381 if (lhs->exponent<=rhs->exponent) {
4412 /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
4419 maxdigits=rhs->digits+reqdigits-1;
4433 /* Extend the lhs and rhs to full long subtraction length. The lhs */
4435 /* subtract in place is always possible. The rhs (var2) has */
4444 /* rhs (var2) is left-aligned with var1 at the start */
4445 var2ulen=var1units; /* rhs logical length (units) */
4446 var2units=D2U(rhs->digits); /* rhs actual length (units) */
4447 var2=rhs->lsu; /* -> rhs array */
4488 maxexponent=lhs->exponent-rhs->exponent; /* save */
4663 if (rhs->exponent<exp) exp=rhs->exponent;
4682 postshift=var1initpad+exponent-lhs->exponent+rhs->exponent;
4692 exponent=lhs->exponent; /* exponent is smaller of lhs & rhs */
4693 if (rhs->exponent<exponent) exponent=rhs->exponent;
4696 /* (looking just at coefficients) is > rhs/2, or == rhs/2 and */
4697 /* the integer was odd then the result should be rem-rhs. */
4711 compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
4712 rhs->exponent-exponent);
4751 /* rem-rhs is needed; the sign will invert. Again, var1 */
4753 exp=rhs->exponent-exponent; /* RHS padding needed */
4759 rhs->lsu, D2U(rhs->digits),
4801 /* rhs is B */
4832 const decNumber *rhs, decContext *set,
4866 uInt *zrhi=zrhibuff; /* -> rhs array */
4893 if (decCheckOperands(res, lhs, rhs, set)) return res;
4897 bits=(uByte)((lhs->bits^rhs->bits)&DECNEG);
4902 decNaNs(res, lhs, rhs, set, status);
4906 ||((rhs->bits & DECINF)==0 && ISZERO(rhs))) {
4914 /* module], use the shorter number as the multiplier (rhs) and */
4917 if (lhs->digits<rhs->digits) { /* swap... */
4919 lhs=rhs;
4920 rhs=hold;
4932 if (rhs->digits>set->digits) {
4933 allocrhs=decRoundOperand(rhs, set, status);
4935 rhs=allocrhs;
4945 if (rhs->digits>NEEDTWO) { /* use fastpath... */
4948 irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
4991 for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
5018 for (rip=zrhi; rip<=rmsi; rip++) { /* over each item in rhs */
5068 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5084 mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
5086 for (mer=rhs->lsu; mer<mermsup; mer++) {
5119 exponent=lhs->exponent+rhs->exponent; /* calculate exponent */
5120 if (lhs->exponent<0 && rhs->exponent<0 && exponent>0)
5148 /* rhs is A */
5157 /* 2*DEC_MAX_MATH (1999998), and the rhs must be within these */
5211 /* than ten) or when rhs is short. As an example, the adjustment */
5221 decNumber * decExpOp(decNumber *res, const decNumber *rhs,
5228 const decNumber *x=rhs; /* (may point to safe copy later) */
5236 decNumber *allocrhs=NULL; /* non-NULL if rhs buffer allocated */
5258 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
5263 if (decNumberIsInfinite(rhs)) { /* an infinity */
5264 if (decNumberIsNegative(rhs)) /* -Infinity -> +0 */
5266 else decNumberCopy(res, rhs); /* +Infinity -> self */
5268 else decNaNs(res, rhs, NULL, set, status); /* a NaN */
5271 if (ISZERO(rhs)) { /* zeros -> exact 1 */
5293 if (decNumberIsNegative(rhs)) d->exponent--; /* negative case */
5294 comp=decCompare(d, rhs, 1); /* signless compare */
5298 if (comp>=0) { /* rhs < d */
5317 h=rhs->exponent+rhs->digits;
5319 /* h=8 then exp(|rhs|) will be at least exp(1E+7) which is at */
5329 if (decNumberIsNegative(rhs)) a->exponent=-2; /* make 0.02 */
5334 Int maxlever=(rhs->digits>8?1:0);
5346 Int use=-rhs->digits-lever; /* exponent to use for RHS */
5353 if (rhs->exponent!=use) {
5355 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5363 decNumberCopy(newrhs, rhs); /* copy to safe space */
5526 /* rhs is A */
5540 /* DEC_MAX_MATH+11 (1000010), and the rhs must be within these */
5581 decNumber * decLnOp(decNumber *res, const decNumber *rhs,
5586 Int r; /* rhs=f*10**r [see below] */
5606 if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
5611 if (decNumberIsInfinite(rhs)) { /* an infinity */
5612 if (decNumberIsNegative(rhs)) /* -Infinity -> error */
5614 else decNumberCopy(res, rhs); /* +Infinity -> self */
5616 else decNaNs(res, rhs, NULL, set, status); /* a NaN */
5619 if (ISZERO(rhs)) { /* +/- zeros -> -Infinity */
5625 if (decNumberIsNegative(rhs)) { /* -x -> error */
5629 /* Here, rhs is positive, finite, and in range */
5632 if (rhs->exponent==0 && set->digits<=40) {
5634 if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
5636 if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
5643 if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
5653 /* the rhs is 'over-precise' then allow for all its digits to */
5654 /* potentially participate (consider an rhs where all the excess */
5655 /* digits are 9s) so in this case use rhs->digits+2. */
5656 p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
5661 /* rhs->digits+p digits. They are also made big enough for 16 */
5672 pp=p+rhs->digits;
5685 /* 10**r. Then, rhs=f*10**r and 0.1<=f<1, and */
5692 r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
5697 /* now get top two digits of rhs into b by simple truncate and */
5701 decCopyFit(b, rhs, &aset, &residue, &ignore); /* copy & shorten */
5712 /* When rhs is at or near Nmax the estimate will be low, so we */
5733 bset.digits=pp+rhs->digits; /* wider context */
5747 /* now multiply by rhs and subtract 1, at the wider precision */
5748 decMultiplyOp(b, b, rhs, &bset, &ignore); /* b=b*rhs */
5763 decCompareOp(&cmp, rhs, &numone, &aset, COMPARE, &ignore); /* rhs=1 ? */
5779 bset.digits=pp+rhs->digits; /* wider context */
5786 (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
5814 /* rhs is B, the requested exponent */
5826 const decNumber *rhs, decContext *set,
5830 decNumber *allocrhs=NULL; /* .., rhs */
5832 const decNumber *inrhs=rhs; /* save original rhs */
5839 if (decCheckOperands(res, lhs, rhs, set)) return res;
5851 if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
5852 allocrhs=decRoundOperand(rhs, set, status);
5854 rhs=allocrhs;
5864 decNaNs(res, lhs, rhs, set, status);
5866 else if ((lhs->bits ^ rhs->bits) & DECINF)
5875 else { /* rescale -- use value of rhs */
5876 /* Original rhs must be an integer that fits and is in range, */
5987 /* rhs is B */
5999 const decNumber *rhs, decContext *set,
6003 decNumber *allocrhs=NULL; /* .., rhs */
6009 if (decCheckOperands(res, lhs, rhs, set)) return res;
6021 if (rhs->digits>set->digits) {
6022 allocrhs=decRoundOperand(rhs, set, status);
6024 rhs=allocrhs;
6032 if (decNumberIsNegative(lhs) & !decNumberIsNegative(rhs)) {
6036 if (!decNumberIsNegative(lhs) & decNumberIsNegative(rhs)) {
6044 merged=(lhs->bits | rhs->bits) & (DECSNAN | DECNAN);
6053 else if (!decNumberIsNaN(rhs)) result=+1;
6055 else if (decNumberIsSNaN(lhs) && decNumberIsQNaN(rhs)) result=-1;
6056 else if (decNumberIsQNaN(lhs) && decNumberIsSNaN(rhs)) result=+1;
6060 rhs->lsu, D2U(rhs->digits), 0);
6070 if (!decNumberIsNaN(lhs) || !decNumberIsNaN(rhs)) {
6073 if (lhs->bits & DECNAN) result=-1; /* pick rhs */
6079 decNaNs(res, lhs, rhs, set, status); /* propagate NaN */
6083 if (op==COMPMAXMAG || op==COMPMINMAG) result=decCompare(lhs, rhs, 1);
6084 else result=decCompare(lhs, rhs, 0); /* sign matters */
6093 if (lhs->exponent!=rhs->exponent) {
6094 if (lhs->exponent<rhs->exponent) result=-1;
6113 uByte srhs=(rhs->bits & DECNEG);
6122 if (slhs) result=-1; /* rhs is max */
6126 if (lhs->exponent<rhs->exponent) result=+1;
6131 if (lhs->exponent>rhs->exponent) result=+1;
6138 choice=(result>0 ? lhs : rhs); /* choose */
6163 static Int decCompare(const decNumber *lhs, const decNumber *rhs,
6166 Int sigr; /* rhs signum */
6172 if (ISZERO(rhs)) return result; /* LHS wins or both 0 */
6179 sigr=1; /* compute signum(rhs) */
6180 if (ISZERO(rhs)) sigr=0;
6181 else if (decNumberIsNegative(rhs)) sigr=-1;
6188 if ((lhs->bits | rhs->bits) & DECINF) { /* one or more infinities */
6189 if (decNumberIsInfinite(rhs)) {
6191 else result=-result; /* only rhs infinite */
6196 if (lhs->exponent>rhs->exponent) { /* LHS exponent larger */
6199 lhs=rhs;
6200 rhs=temp;
6204 rhs->lsu, D2U(rhs->digits),
6205 rhs->exponent-lhs->exponent);
7495 /* rhs is the operand to check */
7508 static uInt decCheckMath(const decNumber *rhs, decContext *set,
7514 else if ((rhs->digits>DEC_MAX_MATH
7515 || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
7516 || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
7517 && !ISZERO(rhs)) *status|=DEC_Invalid_operation;
7675 /* rhs is the second operand, or NULL if none */
7685 const decNumber *rhs, decContext *set,
7691 else if (rhs==NULL);
7692 else if (rhs->bits & DECSNAN) {
7693 lhs=rhs;
7697 else lhs=rhs;
7896 /* rhs is the second (may be DECUNUSED) */
7905 const decNumber *rhs, decContext *set) {
7930 if (!bad && rhs!=DECUNUSED) bad=(decCheckNumber(rhs));