Lines Matching defs:lhs

156 /*	lhs -- left hand side (operand, of an operation)	      */
228 static Int decCompare(const decNumber *lhs, const decNumber *rhs, Flag);
279 #define SPECIALARGS ((lhs->bits | rhs->bits) & DECSPECIAL)
926 /* lhs is A */
933 decNumber * decNumberAdd(decNumber *res, const decNumber *lhs,
936 decAddOp(res, lhs, rhs, set, 0, &status);
950 /* lhs is A */
959 decNumber * decNumberAnd(decNumber *res, const decNumber *lhs,
966 if (decCheckOperands(res, lhs, rhs, set)) return res;
969 if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
976 ua=lhs->lsu; /* bottom-up */
979 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
1021 /* lhs is A */
1027 decNumber * decNumberCompare(decNumber *res, const decNumber *lhs,
1030 decCompareOp(res, lhs, rhs, set, COMPARE, &status);
1041 /* lhs is A */
1047 decNumber * decNumberCompareSignal(decNumber *res, const decNumber *lhs,
1050 decCompareOp(res, lhs, rhs, set, COMPSIG, &status);
1061 /* lhs is A */
1068 decNumber * decNumberCompareTotal(decNumber *res, const decNumber *lhs,
1071 decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
1082 /* lhs is A */
1089 decNumber * decNumberCompareTotalMag(decNumber *res, const decNumber *lhs,
1100 if (decCheckOperands(res, lhs, rhs, set)) return res;
1105 if (decNumberIsNegative(lhs)) { /* lhs<0 */
1107 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
1115 decNumberCopy(a, lhs); /* copy content */
1117 lhs=a; /* use copy from here on */
1133 decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
1148 /* lhs is A */
1154 decNumber * decNumberDivide(decNumber *res, const decNumber *lhs,
1157 decDivideOp(res, lhs, rhs, set, DIVIDE, &status);
1171 /* lhs is A */
1177 decNumber * decNumberDivideInteger(decNumber *res, const decNumber *lhs,
1180 decDivideOp(res, lhs, rhs, set, DIVIDEINT, &status);
1256 /* lhs is A */
1266 decNumber * decNumberFMA(decNumber *res, const decNumber *lhs,
1278 if (decCheckOperands(res, lhs, rhs, set)) return res;
1289 if ((!decNumberIsSpecial(lhs) && decCheckMath(lhs, set, &status))
1294 dcmul.digits=lhs->digits+rhs->digits; /* just enough */
1310 decMultiplyOp(acc, lhs, rhs, &dcmul, &status);
1694 /* lhs is A */
1700 decNumber * decNumberMax(decNumber *res, const decNumber *lhs,
1703 decCompareOp(res, lhs, rhs, set, COMPMAX, &status);
1717 /* lhs is A */
1723 decNumber * decNumberMaxMag(decNumber *res, const decNumber *lhs,
1726 decCompareOp(res, lhs, rhs, set, COMPMAXMAG, &status);
1740 /* lhs is A */
1746 decNumber * decNumberMin(decNumber *res, const decNumber *lhs,
1749 decCompareOp(res, lhs, rhs, set, COMPMIN, &status);
1763 /* lhs is A */
1769 decNumber * decNumberMinMag(decNumber *res, const decNumber *lhs,
1772 decCompareOp(res, lhs, rhs, set, COMPMINMAG, &status);
1893 /* lhs is A */
1899 decNumber * decNumberNextToward(decNumber *res, const decNumber *lhs,
1906 if (decCheckOperands(res, lhs, rhs, set)) return res;
1909 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) {
1910 decNaNs(res, lhs, rhs, set, &status);
1913 result=decCompare(lhs, rhs, 0); /* sign matters */
1916 if (result==0) decNumberCopySign(res, lhs, rhs); /* easy */
1919 if (result<0) { /* lhs<rhs, do nextplus */
1921 if ((lhs->bits&(DECINF|DECNEG))==(DECINF|DECNEG)) {
1929 else { /* lhs>rhs, do nextminus */
1931 if ((lhs->bits&(DECINF|DECNEG))==DECINF) {
1941 decAddOp(res, lhs, &dtiny, &workset, sub, &status); /* + or - */
1958 /* lhs is A */
1967 decNumber * decNumberOr(decNumber *res, const decNumber *lhs,
1974 if (decCheckOperands(res, lhs, rhs, set)) return res;
1977 if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
1983 ua=lhs->lsu; /* bottom-up */
1986 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
2061 /* lhs is A */
2067 decNumber * decNumberMultiply(decNumber *res, const decNumber *lhs,
2070 decMultiplyOp(res, lhs, rhs, set, &status);
2084 /* lhs is A */
2104 decNumber * decNumberPower(decNumber *res, const decNumber *lhs,
2107 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
2131 /* same again for possible 1/lhs calculation */
2135 if (decCheckOperands(res, lhs, rhs, set)) return res;
2141 if (lhs->digits>reqdigits) {
2142 alloclhs=decRoundOperand(lhs, set, &status);
2144 lhs=alloclhs;
2155 /* handle NaNs and rhs Infinity (lhs infinity is harder) */
2157 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) { /* NaNs */
2158 decNaNs(res, lhs, rhs, set, &status);
2162 if (decNumberIsNegative(lhs) /* lhs<0 */
2163 && !decNumberIsZero(lhs)) /* .. */
2165 else { /* lhs >=0 */
2168 decNumberCompare(dac, lhs, &dnOne, set); /* lhs ? 1 */
2170 if (decNumberIsNegative(dac)) { /* lhs<1 */
2173 else if (dac->lsu[0]==0) { /* lhs=1 */
2181 else { /* lhs>1 */
2184 } /* lhs>=0 */
2186 /* [lhs infinity drops through] */
2198 if (decNumberIsNegative(lhs) /* -x .. */
2202 if (decNumberIsInfinite(lhs)) { /* [NaNs already handled] */
2208 if (!rhsint && decNumberIsNegative(lhs)) {
2218 if (decNumberIsZero(lhs)) {
2244 /* here both lhs and rhs are finite; rhs==0 is handled in the */
2247 /* any -ve lhs is bad, as is either operand or context out of */
2249 if (decNumberIsNegative(lhs)) {
2252 if (decCheckMath(lhs, set, &status)
2260 /* calculate the result using exp(ln(lhs)*rhs), which can */
2262 /* is enough to contain the full information in the lhs (which */
2270 aset.digits=MAXI(lhs->digits, set->digits)+6+4;
2296 /* [needbytes also used below if 1/lhs needed] */
2310 decLnOp(dac, lhs, &aset, &status); /* dac=ln(lhs) */
2311 /* [no error possible, as lhs 0 already handled] */
2334 /* invert the lhs now rather than inverting the result later */
2339 if (set->extended) { /* need to calculate 1/lhs */
2341 /* divide lhs into 1, putting result in dac [dac=1/dac] */
2342 decDivideOp(dac, &dnOne, lhs, &aset, DIVIDE, &status);
2343 /* now locate or allocate space for the inverted lhs */
2352 decNumberCopy(inv, dac); /* copy the 1/lhs */
2354 lhs=inv; /* .. and go forward with new lhs */
2372 decMultiplyOp(dac, dac, lhs, &aset, &status); /* dac=dac*x */
2440 /* lhs is A, the number to adjust */
2449 decNumber * decNumberQuantize(decNumber *res, const decNumber *lhs,
2452 decQuantizeOp(res, lhs, rhs, set, 1, &status);
2528 /* lhs is A, the number to adjust */
2537 decNumber * decNumberRescale(decNumber *res, const decNumber *lhs,
2540 decQuantizeOp(res, lhs, rhs, set, 0, &status);
2551 /* lhs is A */
2557 decNumber * decNumberRemainder(decNumber *res, const decNumber *lhs,
2560 decDivideOp(res, lhs, rhs, set, REMAINDER, &status);
2574 /* lhs is A */
2580 decNumber * decNumberRemainderNear(decNumber *res, const decNumber *lhs,
2583 decDivideOp(res, lhs, rhs, set, REMNEAR, &status);
2598 /* lhs is A */
2604 /* the exponent or the sign of A. If lhs->digits is less than */
2616 decNumber * decNumberRotate(decNumber *res, const decNumber *lhs,
2622 if (decCheckOperands(res, lhs, rhs, set)) return res;
2626 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2627 decNaNs(res, lhs, rhs, set, &status);
2638 decNumberCopy(res, lhs);
2642 && !decNumberIsInfinite(res)) { /* lhs was infinite */
2732 /* lhs is a number to test */
2737 decNumber * decNumberSameQuantum(decNumber *res, const decNumber *lhs,
2742 if (decCheckOperands(res, lhs, rhs, DECUNCONT)) return res;
2746 if (decNumberIsNaN(lhs) && decNumberIsNaN(rhs)) ret=1;
2747 else if (decNumberIsInfinite(lhs) && decNumberIsInfinite(rhs)) ret=1;
2750 else if (lhs->exponent==rhs->exponent) ret=1;
2764 /* lhs is A, the number to adjust */
2772 decNumber * decNumberScaleB(decNumber *res, const decNumber *lhs,
2779 if (decCheckOperands(res, lhs, rhs, set)) return res;
2782 /* Handle special values except lhs infinite */
2783 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2784 decNaNs(res, lhs, rhs, set, &status);
2789 /* lhs is a number; rhs is a finite with q==0 */
2796 decNumberCopy(res, lhs); /* all done if infinite lhs */
2814 /* lhs is A */
2829 decNumber * decNumberShift(decNumber *res, const decNumber *lhs,
2835 if (decCheckOperands(res, lhs, rhs, set)) return res;
2839 if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
2840 decNaNs(res, lhs, rhs, set, &status);
2851 decNumberCopy(res, lhs);
3286 /* lhs is A */
3292 decNumber * decNumberSubtract(decNumber *res, const decNumber *lhs,
3296 decAddOp(res, lhs, rhs, set, DECNEG, &status);
3372 /* lhs is A */
3381 decNumber * decNumberXor(decNumber *res, const decNumber *lhs,
3388 if (decCheckOperands(res, lhs, rhs, set)) return res;
3391 if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
3397 ua=lhs->lsu; /* bottom-up */
3400 msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
3575 /* lhs is A */
3581 decNumber * decNumberCopySign(decNumber *res, const decNumber *lhs,
3588 decNumberCopy(res, lhs);
3920 /* lhs is A */
3949 static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
3953 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
3971 if (decCheckOperands(res, lhs, rhs, set)) return res;
3978 if (lhs->digits>reqdigits) {
3979 alloclhs=decRoundOperand(lhs, set, status);
3981 lhs=alloclhs;
3993 diffsign=(Flag)((lhs->bits^rhs->bits^negate)&DECNEG);
3998 decNaNs(res, lhs, rhs, set, status);
4000 if (decNumberIsInfinite(lhs)) { /* LHS is infinity */
4006 bits=lhs->bits & DECNEG; /* get sign from LHS */
4017 if (ISZERO(lhs)) {
4019 Int lexp=lhs->exponent; /* save in case LHS==RES */
4020 bits=lhs->bits; /* .. */
4053 if (ISZERO(rhs)) { /* [lhs is non-zero] */
4058 decCopyFit(res, lhs, set, &residue, status); /* copy (as needed) */
4083 padding=rhs->exponent-lhs->exponent;
4093 && lhs->digits<=reqdigits) {
4094 Int partial=*lhs->lsu;
4098 && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
4099 partial<(Int)powers[lhs->digits])) { /* .. */
4100 if (res!=lhs) decNumberCopy(res, lhs); /* not in place */
4109 if (res!=lhs) decNumberCopy(res, lhs); /* not in place */
4119 /* Now align (pad) the lhs or rhs so they can be added or */
4127 bits=lhs->bits; /* assume sign is that of LHS */
4140 t=lhs; lhs=rhs; rhs=t;
4144 /* If, after pad, rhs would be longer than lhs by digits+1 or */
4145 /* more then lhs cannot affect the answer, except as a residue, */
4147 if (rhs->digits+padding > lhs->digits+reqdigits+1) {
4174 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4199 res->exponent=lhs->exponent; /* .. operands (even if aliased) */
4202 decDumpAr('A', lhs->lsu, D2U(lhs->digits));
4208 res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
4302 /* lhs is A */
4359 /* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/
4364 const decNumber *lhs, const decNumber *rhs,
4367 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
4408 if (decCheckOperands(res, lhs, rhs, set)) return res;
4415 if (lhs->digits>reqdigits) {
4416 alloclhs=decRoundOperand(lhs, set, status);
4418 lhs=alloclhs;
4429 bits=(lhs->bits^rhs->bits)&DECNEG; /* assumed sign for divisions */
4434 decNaNs(res, lhs, rhs, set, status);
4438 if (decNumberIsInfinite(lhs)) { /* LHS (dividend) is infinite */
4452 /* result is [finished clone of] lhs */
4453 decCopyFit(res, lhs, set, &residue, status);
4472 if (ISZERO(lhs)) {
4473 decNumberZero(res); /* [after lhs test] */
4486 /* handle 0 lhs (0/x) */
4487 if (ISZERO(lhs)) { /* 0/x [x!=0] */
4494 exponent=lhs->exponent-rhs->exponent; /* ideal exponent */
4495 decNumberCopy(res, lhs); /* [zeros always fit] */
4506 decNumberCopy(res, lhs); /* [zeros always fit] */
4518 exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
4531 /* fastpath remainders so long as the lhs has the smaller */
4533 if (lhs->exponent<=rhs->exponent) {
4536 /* clone of] lhs (r = x - 0*y) */
4538 decCopyFit(res, lhs, set, &residue, status);
4565 /* or (lhs->digits) -- to allow for long lhs */
4572 if (lhs->digits>maxdigits) maxdigits=lhs->digits;
4585 /* Extend the lhs and rhs to full long subtraction length. The lhs */
4592 source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
4593 for (target=msu1; source>=lhs->lsu; source--, target--) *target=*source;
4629 var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
4640 maxexponent=lhs->exponent-rhs->exponent; /* save */
4809 bits=lhs->bits; /* remainder sign is always as lhs */
4814 Int exp=lhs->exponent; /* save min(exponents) */
4834 postshift=var1initpad+exponent-lhs->exponent+rhs->exponent;
4844 exponent=lhs->exponent; /* exponent is smaller of lhs & rhs */
4952 /* lhs is A */
4983 static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,
5015 uInt *zlhi=zlhibuff; /* -> lhs array */
5045 if (decCheckOperands(res, lhs, rhs, set)) return res;
5049 bits=(uByte)((lhs->bits^rhs->bits)&DECNEG);
5054 decNaNs(res, lhs, rhs, set, status);
5057 if (((lhs->bits & DECINF)==0 && ISZERO(lhs))
5067 /* the longer as the multiplicand (lhs) to minimise the number of */
5069 if (lhs->digits<rhs->digits) { /* swap... */
5070 const decNumber *hold=lhs;
5071 lhs=rhs;
5079 if (lhs->digits>set->digits) {
5080 alloclhs=decRoundOperand(lhs, set, status);
5082 lhs=alloclhs;
5099 ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
5138 for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
5171 lp=zacc+(rip-zrhi); /* where to add the lhs */
5172 for (lip=zlhi; lip<=lmsi; lip++, lp++) { /* over each item in lhs */
5220 needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
5235 madlength=D2U(lhs->digits); /* this won't change */
5242 lhs->lsu, madlength, 0,
5271 exponent=lhs->exponent+rhs->exponent; /* calculate exponent */
5272 if (lhs->exponent<0 && rhs->exponent<0 && exponent>0)
5966 /* lhs is A, the number to adjust */
5978 static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs,
5982 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
5992 if (decCheckOperands(res, lhs, rhs, set)) return res;
5999 if (lhs->digits>reqdigits) {
6000 alloclhs=decRoundOperand(lhs, set, status);
6002 lhs=alloclhs;
6017 decNaNs(res, lhs, rhs, set, status);
6019 else if ((lhs->bits ^ rhs->bits) & DECINF)
6021 /* both infinity: return lhs */
6022 else decNumberCopy(res, lhs); /* [nop if in place] */
6047 if (ISZERO(lhs)) { /* zero coefficient unchanged */
6048 decNumberCopy(res, lhs); /* [nop if in place] */
6054 else { /* non-zero lhs */
6055 Int adjust=reqexp-lhs->exponent; /* digit adjustment needed */
6057 if ((lhs->digits-adjust)>reqdigits) {
6067 workset.digits=lhs->digits-adjust; /* set requested length */
6069 decCopyFit(res, lhs, &workset, &residue, status); /* fit to result */
6093 decNumberCopy(res, lhs); /* [it will fit] */
6139 /* lhs is A */
6151 static decNumber *decCompareOp(decNumber *res, const decNumber *lhs,
6155 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
6162 if (decCheckOperands(res, lhs, rhs, set)) return res;
6169 if (lhs->digits>set->digits) {
6170 alloclhs=decRoundOperand(lhs, set, status);
6172 lhs=alloclhs;
6185 if (decNumberIsNegative(lhs) && !decNumberIsNegative(rhs)) {
6189 if (!decNumberIsNegative(lhs) && decNumberIsNegative(rhs)) {
6197 merged=(lhs->bits | rhs->bits) & (DECSNAN | DECNAN);
6205 if (!decNumberIsNaN(lhs)) result=-1;
6208 else if (decNumberIsSNaN(lhs) && decNumberIsQNaN(rhs)) result=-1;
6209 else if (decNumberIsQNaN(lhs) && decNumberIsSNaN(rhs)) result=+1;
6212 result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6216 if (decNumberIsNegative(lhs)) result=-result;
6223 if (!decNumberIsNaN(lhs) || !decNumberIsNaN(rhs)) {
6226 if (lhs->bits & DECNAN) result=-1; /* pick rhs */
6227 else result=+1; /* pick lhs */
6232 decNaNs(res, lhs, rhs, set, status); /* propagate NaN */
6236 if (op==COMPMAXMAG || op==COMPMINMAG) result=decCompare(lhs, rhs, 1);
6237 else result=decCompare(lhs, rhs, 0); /* sign matters */
6246 if (lhs->exponent!=rhs->exponent) {
6247 if (lhs->exponent<rhs->exponent) result=-1;
6249 if (decNumberIsNegative(lhs)) result=-result;
6265 uByte slhs=(lhs->bits & DECNEG);
6276 else result=+1; /* lhs is max */
6279 if (lhs->exponent<rhs->exponent) result=+1;
6281 /* [if equal, use lhs, technically identical] */
6284 if (lhs->exponent>rhs->exponent) result=+1;
6291 choice=(result>0 ? lhs : rhs); /* choose */
6316 static Int decCompare(const decNumber *lhs, const decNumber *rhs,
6322 result=1; /* assume signum(lhs) */
6323 if (ISZERO(lhs)) result=0;
6331 if (result && decNumberIsNegative(lhs)) result=-1;
6341 if ((lhs->bits | rhs->bits) & DECINF) { /* one or more infinities */
6343 if (decNumberIsInfinite(lhs)) result=0;/* both infinite */
6349 if (lhs->exponent>rhs->exponent) { /* LHS exponent larger */
6351 const decNumber *temp=lhs;
6352 lhs=rhs;
6356 compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
6358 rhs->exponent-lhs->exponent);
7826 /* lhs is the first operand */
7836 static decNumber * decNaNs(decNumber *res, const decNumber *lhs,
7841 if (lhs->bits & DECSNAN)
7845 lhs=rhs;
7848 else if (lhs->bits & DECNAN);
7849 else lhs=rhs;
7852 if (lhs->digits<=set->digits) decNumberCopy(res, lhs); /* easy */
7857 res->bits=lhs->bits; /* need sign etc. */
7859 for (ur=res->lsu, ul=lhs->lsu; ur<uresp1; ur++, ul++) *ur=*ul;
8079 /* lhs is the first operand (may be DECUNRESU) */
8088 static Flag decCheckOperands(decNumber *res, const decNumber *lhs,
8113 if (!bad && lhs!=DECUNUSED) bad=(decCheckNumber(lhs));