68 size_t saveFuzz, saveDigits;
70 if (argCount == 0)
return this;
75 saveFuzz = CurrentActivation->
fuzz();
76 saveDigits = CurrentActivation->
digits();
85 for (arg=0; arg < argCount; arg++)
87 nextObject = args[arg];
93 CurrentActivation->
setFuzz(saveFuzz);
139 CurrentActivation->
setFuzz(saveFuzz);
145 CurrentActivation->
setFuzz(saveFuzz);
165 resultDigits = this->
length;
173 while (carry && resultDigits-- > 0)
182 RoundNum = *NumPtr + carry;
185 *NumPtr-- = (char)RoundNum;
237 resultVal = this->
exp + this->
length - 1;
289 if (this->
length > NumberDigits)
291 this->
length = NumberDigits;
293 this->
exp += this->
length - NumberDigits;
305 return(
char *)memcpy(((result + resultLen - 1) - this->
length), NumPtr, this->
length);
317 while (!*AccumPtr && this->
length>1)
336 if (resultPtr == NULL)
348 if (this->
length > NumberDigits)
350 size_t extra = this->
length - NumberDigits;
351 this->
length = NumberDigits;
368 if (!*resultPtr && this->
length == 1)
375 resultVal = this->
exp + this->
length - 1;
397 if (newObj->
length > NumberDigits)
405 newObj->
exp += newObj->
length - NumberDigits;
406 newObj->
length = NumberDigits;
407 if (rounding ==
ROUND)
441 if (newObj->
length > numberDigits)
446 if (newObj->
length > targetLength)
450 newObj->exp += newObj->
length - targetLength;
451 newObj->
length = targetLength;
452 if (rounding ==
ROUND)
455 newObj->mathRound(newObj->number);
467 unsigned int operation,
468 size_t NumberDigits )
474 char *leftPtr,*rightPtr,*resultPtr;
475 char *resultBuffer = NULL;
476 int right_sign, carry, addDigit, rc;
480 wholenumber_t aLeftExp, aRightExp, rightExp, leftExp, MinExp;
481 size_t rightLength, leftLength;
483 size_t maxLength = NumberDigits + 1;
492 rightExp = right->
exp;
494 leftLength = left->
length;
495 rightLength = right->
length;
497 if (leftLength > NumberDigits)
501 if (leftLength > maxLength)
503 leftExp += leftLength - maxLength;
504 leftLength = maxLength;
508 if (rightLength > NumberDigits)
512 if (rightLength > maxLength)
515 rightExp += rightLength - maxLength;
516 rightLength = maxLength;
521 if (leftExp <= rightExp)
531 aLeftExp = leftExp - MinExp;
532 aRightExp = rightExp - MinExp;
533 right_sign = right->
sign;
542 else if (right->
sign==0)
570 result = temp1->
clone();
574 if ((temp1 == right) && (operation ==
OT_MINUS))
587 right_sign = -right_sign;
591 if (right_sign != left->
sign)
594 if (((leftLength == rightLength) && (leftExp == rightExp)) &&
607 ResultSize = maxLength;
615 leftPtr = left->
number + leftLength - 1;
617 rightPtr = right->
number + rightLength - 1;
632 if (LadjustDigits > 0 || RadjustDigits >0 )
634 if (LadjustDigits >= RadjustDigits)
637 adjustDigits = LadjustDigits;
641 adjustDigits = RadjustDigits;
652 aLeftExp -= adjustDigits;
654 rightPtr = rightPtr-adjustDigits;
655 rightExp += adjustDigits;
656 rightLength -= adjustDigits;
662 rightPtr = rightPtr-aLeftExp;
663 rightExp += aLeftExp;
664 rightLength -= adjustDigits;
665 adjustDigits -= aLeftExp;
674 aRightExp -= adjustDigits;
676 leftPtr = leftPtr-adjustDigits;
677 leftExp += adjustDigits;
678 leftLength -= adjustDigits;
684 leftPtr = leftPtr-aRightExp;
685 leftExp += aRightExp;
686 leftLength -= adjustDigits;
687 adjustDigits -= aRightExp;
694 leftExp += adjustDigits;
696 leftPtr = leftPtr-adjustDigits;
697 rightExp += adjustDigits;
698 rightPtr = rightPtr - adjustDigits;
703 resultBuffer = resultBufFast;
711 resultPtr = resultBuffer + NumberDigits*2;
733 if (rightPtr >= right->
number)
735 *resultPtr-- = *rightPtr--;
744 result->
exp = rightExp;
755 if (leftPtr >= left->
number)
757 *resultPtr-- = *leftPtr--;
765 result->
exp = leftExp;
769 result->
exp = leftExp;
772 while ( (leftPtr >= left->
number) &&
773 (rightPtr >= right->
number) )
779 addDigit = carry + (*leftPtr--) + *(rightPtr--);
790 *resultPtr-- = (char)addDigit;
797 while (leftPtr >= left->
number)
800 addDigit = carry + (*leftPtr--);
811 *resultPtr-- = (char)addDigit;
815 while (rightPtr >= right->
number)
818 addDigit = carry + (*rightPtr--);
829 *resultPtr-- = (char)addDigit;
844 if ((aLeftExp + leftLength)>(aRightExp + rightLength))
847 subtractNumbers(left, leftPtr, aLeftExp, right, rightPtr, aRightExp, result, &resultPtr);
852 result->
exp = rightExp;
856 result->
exp = leftExp;
862 else if ((aLeftExp + leftLength)<(aRightExp + rightLength))
865 subtractNumbers(right, rightPtr, aRightExp, left, leftPtr, aLeftExp, result, &resultPtr);
870 result->
exp = rightExp;
874 result->
exp = leftExp;
877 result->
sign = right_sign;
886 else if (rightLength < leftLength)
892 if ((rc = memcmp(right->
number, left->
number, rightLength)) > 0)
895 subtractNumbers(right, rightPtr, aRightExp, left, leftPtr, aLeftExp, result, &resultPtr);
896 result->
sign = right_sign;
901 subtractNumbers(left, leftPtr, aLeftExp, right, rightPtr, aRightExp, result, &resultPtr);
904 result->
exp = leftExp;
912 if ((rc = memcmp(left->
number, right->
number, leftLength)) > 0)
915 subtractNumbers(left, leftPtr, aLeftExp, right, rightPtr, aRightExp, result, &resultPtr);
916 result->
exp = rightExp;
925 subtractNumbers(right, rightPtr, aRightExp, left, leftPtr, aLeftExp, result, &resultPtr);
926 result->
exp = rightExp;
929 result->
sign = right_sign;
933 if (leftLength < rightLength)
937 subtractNumbers(right, rightPtr, aRightExp, left, leftPtr, aLeftExp, result, &resultPtr);
938 result->
exp = rightExp;
941 result->
sign = right_sign;
972 const char *largerPtr,
975 const char *smallerPtr,
985 int borrow, subDigit;
988 resultPtr = *presultPtr;
1003 while (aLargerExp--)
1015 if (smallerPtr >= smaller->
number)
1017 subDigit = *smallerPtr--;
1027 subDigit = borrow + 10 - subDigit;
1040 *resultPtr-- = (char)subDigit;
1044 while (aSmallerExp--)
1060 if (largerPtr >= larger->
number)
1062 *resultPtr-- = *largerPtr--;
1066 *resultPtr-- =
'\0';
1075 while (smallerPtr >= smaller->
number)
1081 subDigit = borrow + (*largerPtr--) - *(smallerPtr--);
1092 *resultPtr-- = (char)subDigit;
1099 while (largerPtr >= larger->
number)
1101 subDigit = borrow + (*largerPtr--);
1112 *resultPtr-- = (char)subDigit;
1116 *presultPtr = resultPtr;
1135 *Value-- = (char)Digit;
1140 *Value-- = (char)Digit;
1144 if (Value < HighDigit)
1168 while (OutPtr > HighDigit)
1171 Digit = (
unsigned int )((*OutPtr * 10) + Carry);
1174 Carry = (int)(Digit / 16);
1175 Digit &= (
unsigned int )0x0000000f;
1181 *OutPtr-- = (char)Digit;
1185 *OutPtr-- = (char)Carry;
1202 while (Digit || Carry)
1204 Digit += *Accum + Carry;
1209 *Accum-- = (char)Digit;
1213 *Accum-- = (char)Digit;
1218 if (Accum < HighDigit)
1244 while (OutPtr > HighDigit)
1247 Digit = (
unsigned int )((*OutPtr * 16) + Carry);
1250 Carry = (int)(Digit / 10);
1257 *OutPtr-- = (char)Digit;
1263 *OutPtr-- = (char)Digit;
void reportCondition(RexxString *condition, RexxString *description)
void reportException(wholenumber_t error)
RexxInteger * new_integer(wholenumber_t v)
RexxNumberString * new_numberstring(const char *s, stringsize_t l)
#define Error_Incorrect_method_number
#define Error_Incorrect_call_noarg
#define Error_Overflow_expoverflow
#define Error_Overflow_expunderflow
static RexxActivity *volatile currentActivity
static const wholenumber_t MIN_EXPONENT
static const wholenumber_t MAX_EXPONENT
static const size_t DEFAULT_DIGITS
virtual void setFuzz(size_t)
RexxActivationBase * getTopStackFrame()
char * stripLeadingZeros(char *)
char * adjustNumber(char *, char *, size_t, size_t)
static char * addToBaseTen(int, char *, char *)
RexxInteger * isLessThan(RexxObject *)
RexxNumberString * prepareNumber(size_t, bool)
RexxInteger * isGreaterThan(RexxObject *)
void adjustPrecision(char *, size_t)
static char * multiplyBaseSixteen(char *, char *)
RexxNumberString * clone()
RexxNumberString * maxMin(RexxObject **, size_t, size_t, unsigned int)
RexxNumberString * prepareOperatorNumber(size_t, size_t, bool)
static void subtractNumbers(RexxNumberString *larger, const char *largerPtr, wholenumber_t aLargerExp, RexxNumberString *smaller, const char *smallerPtr, wholenumber_t aSmallerExp, RexxNumberString *result, char **resultPtr)
void setNumericSettings(size_t digits, bool form)
static size_t highBits(size_t)
static char * addToBaseSixteen(int, char *, char *)
static char * multiplyBaseTen(char *, char *)
RexxNumberString * addSub(RexxNumberString *, unsigned int, size_t)
RexxNumberString * numberString()