Browse Source

Rename TempDecimal to Decimal

Renato Golin 13 years ago
parent
commit
589c365d66
6 changed files with 155 additions and 155 deletions
  1. 1 1
      common/workunit/workunit.cpp
  2. 1 1
      roxie/ccd/ccdserver.cpp
  3. 55 55
      rtl/nbcd/nbcd.cpp
  4. 49 49
      rtl/nbcd/nbcd.hpp
  5. 5 5
      rtl/nbcd/nbcds.cpp
  6. 44 44
      rtl/nbcd/nbcdtest.cpp

+ 1 - 1
common/workunit/workunit.cpp

@@ -7208,7 +7208,7 @@ void CLocalWUResult::getResultDecimal(void * val, unsigned len, unsigned precisi
         const char *xmlVal = p->queryProp("xmlValue");
         const char *xmlVal = p->queryProp("xmlValue");
         if (xmlVal)
         if (xmlVal)
         {
         {
-            TempDecimal d;
+            Decimal d;
             d.setString(strlen(xmlVal), xmlVal);
             d.setString(strlen(xmlVal), xmlVal);
             if (isSigned)
             if (isSigned)
                 d.getDecimal(len, precision, val);
                 d.getDecimal(len, precision, val);

+ 1 - 1
roxie/ccd/ccdserver.cpp

@@ -29441,7 +29441,7 @@ public:
                 CriticalBlock b(contextCrit);
                 CriticalBlock b(contextCrit);
                 useContext(sequence).getProp(stepname, x);
                 useContext(sequence).getProp(stepname, x);
             }
             }
-            TempDecimal d;
+            Decimal d;
             d.setString(x.length(), x.str());
             d.setString(x.length(), x.str());
             if (isSigned)
             if (isSigned)
                 d.getDecimal(tlen, precision, tgt);
                 d.getDecimal(tlen, precision, tgt);

+ 55 - 55
rtl/nbcd/nbcd.cpp

@@ -32,19 +32,19 @@ static int signMap[16] = { 0,0,0,0,0,0,0,0,0,0,+1,-1,+1,-1,+1,+1 };
 
 
 
 
 
 
-TempDecimal::TempDecimal(const TempDecimal & other)
+Decimal::Decimal(const Decimal & other)
 {
 {
     memcpy(this, &other, sizeof(*this));
     memcpy(this, &other, sizeof(*this));
 }
 }
 
 
-TempDecimal & TempDecimal::abs()
+Decimal & Decimal::abs()
 {
 {
     negative = false;
     negative = false;
     return *this;
     return *this;
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::add(const TempDecimal & other)
+Decimal & Decimal::add(const Decimal & other)
 {
 {
     if (negative == other.negative)
     if (negative == other.negative)
         return addDigits(other);
         return addDigits(other);
@@ -54,7 +54,7 @@ TempDecimal & TempDecimal::add(const TempDecimal & other)
 
 
 
 
 
 
-TempDecimal & TempDecimal::addDigits(const TempDecimal & other)
+Decimal & Decimal::addDigits(const Decimal & other)
 {
 {
     extendRange(other);
     extendRange(other);
     byte oLo = other.lsb;
     byte oLo = other.lsb;
@@ -93,7 +93,7 @@ TempDecimal & TempDecimal::addDigits(const TempDecimal & other)
     return *this;
     return *this;
 }
 }
 
 
-int TempDecimal::compareNull() const
+int Decimal::compareNull() const
 {
 {
     byte idx;
     byte idx;
     for (idx = lsb; idx <= msb; idx++)
     for (idx = lsb; idx <= msb; idx++)
@@ -104,7 +104,7 @@ int TempDecimal::compareNull() const
 }
 }
 
 
 
 
-int TempDecimal::compare(const TempDecimal & other) const
+int Decimal::compare(const Decimal & other) const
 {
 {
     int lo1, hi1, lo2, hi2;
     int lo1, hi1, lo2, hi2;
     clip(lo1, hi1);
     clip(lo1, hi1);
@@ -142,7 +142,7 @@ int TempDecimal::compare(const TempDecimal & other) const
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::divide(const TempDecimal & other)
+Decimal & Decimal::divide(const Decimal & other)
 {
 {
     //NB: Round towards zero
     //NB: Round towards zero
     int lo1, hi1, lo2, hi2;
     int lo1, hi1, lo2, hi2;
@@ -233,7 +233,7 @@ TempDecimal & TempDecimal::divide(const TempDecimal & other)
 }
 }
 
 
 
 
-void TempDecimal::extendRange(byte oLsb, byte oMsb)
+void Decimal::extendRange(byte oLsb, byte oMsb)
 {
 {
     byte index;
     byte index;
     if (lsb > oLsb)
     if (lsb > oLsb)
@@ -251,15 +251,15 @@ void TempDecimal::extendRange(byte oLsb, byte oMsb)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::modulus(const TempDecimal & other)
+Decimal & Decimal::modulus(const Decimal & other)
 {
 {
-    TempDecimal left(*this);
+    Decimal left(*this);
     left.divide(other).truncate(0).multiply(other);
     left.divide(other).truncate(0).multiply(other);
     return subtract(left);
     return subtract(left);
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::multiply(const TempDecimal & other)
+Decimal & Decimal::multiply(const Decimal & other)
 {
 {
     int low1, high1, low2, high2, lowt, hight;
     int low1, high1, low2, high2, lowt, hight;
 
 
@@ -318,13 +318,13 @@ TempDecimal & TempDecimal::multiply(const TempDecimal & other)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::negate()
+Decimal & Decimal::negate()
 {
 {
     negative = !negative;
     negative = !negative;
     return *this;
     return *this;
 }
 }
 
 
-TempDecimal & TempDecimal::power(unsigned value)
+Decimal & Decimal::power(unsigned value)
 {
 {
     if (value == 0)
     if (value == 0)
         setInt(1);
         setInt(1);
@@ -334,14 +334,14 @@ TempDecimal & TempDecimal::power(unsigned value)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::power(int value)
+Decimal & Decimal::power(int value)
 {
 {
     if ( value >= 0)
     if ( value >= 0)
         return power((unsigned)value);
         return power((unsigned)value);
 
 
 #if 1
 #if 1
     //This probably gives slightly more expected results, but both suffer from rounding errors.
     //This probably gives slightly more expected results, but both suffer from rounding errors.
-    TempDecimal reciprocal;
+    Decimal reciprocal;
     reciprocal.setInt(1);
     reciprocal.setInt(1);
     reciprocal.divide(*this);
     reciprocal.divide(*this);
     set(reciprocal);
     set(reciprocal);
@@ -349,7 +349,7 @@ TempDecimal & TempDecimal::power(int value)
     return *this;
     return *this;
 #else
 #else
     doPower((unsigned)-value);
     doPower((unsigned)-value);
-    TempDecimal reciprocal;
+    Decimal reciprocal;
     reciprocal.setInt(1);
     reciprocal.setInt(1);
     reciprocal.divide(*this);
     reciprocal.divide(*this);
     set(reciprocal);
     set(reciprocal);
@@ -358,7 +358,7 @@ TempDecimal & TempDecimal::power(int value)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::incLSD()
+Decimal & Decimal::incLSD()
 {
 {
     unsigned index = lsb;
     unsigned index = lsb;
     while (index <= msb)
     while (index <= msb)
@@ -376,7 +376,7 @@ TempDecimal & TempDecimal::incLSD()
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::round(int places)
+Decimal & Decimal::round(int places)
 {
 {
     //out of range - either 0 or overflow
     //out of range - either 0 or overflow
     if (places < -maxPrecision)
     if (places < -maxPrecision)
@@ -403,7 +403,7 @@ TempDecimal & TempDecimal::round(int places)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::roundup(int places)
+Decimal & Decimal::roundup(int places)
 {
 {
     if ((places >= maxPrecision) || (zeroDigit - places <= lsb))
     if ((places >= maxPrecision) || (zeroDigit - places <= lsb))
         return *this;
         return *this;
@@ -419,7 +419,7 @@ TempDecimal & TempDecimal::roundup(int places)
 }
 }
 
 
 
 
-void TempDecimal::getPrecision(unsigned & digits, unsigned & precision)
+void Decimal::getPrecision(unsigned & digits, unsigned & precision)
 {
 {
     //Ensures digits>=precision && precision >= 0
     //Ensures digits>=precision && precision >= 0
     unsigned top = msb >= zeroDigit ? msb+1 : zeroDigit;
     unsigned top = msb >= zeroDigit ? msb+1 : zeroDigit;
@@ -428,7 +428,7 @@ void TempDecimal::getPrecision(unsigned & digits, unsigned & precision)
     precision = zeroDigit-low;
     precision = zeroDigit-low;
 }
 }
 
 
-void TempDecimal::getClipPrecision(unsigned & digits, unsigned & precision)
+void Decimal::getClipPrecision(unsigned & digits, unsigned & precision)
 {
 {
     int lo, hi;
     int lo, hi;
     clip(lo, hi);
     clip(lo, hi);
@@ -448,7 +448,7 @@ void TempDecimal::getClipPrecision(unsigned & digits, unsigned & precision)
     }
     }
 }
 }
 
 
-TempDecimal & TempDecimal::setPrecision(byte numDigits, byte precision)
+Decimal & Decimal::setPrecision(byte numDigits, byte precision)
 {
 {
     unsigned char newhigh = zeroDigit + numDigits - precision - 1;
     unsigned char newhigh = zeroDigit + numDigits - precision - 1;
     unsigned char newlow = zeroDigit - precision;
     unsigned char newlow = zeroDigit - precision;
@@ -465,7 +465,7 @@ TempDecimal & TempDecimal::setPrecision(byte numDigits, byte precision)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::subtract(const TempDecimal & other)
+Decimal & Decimal::subtract(const Decimal & other)
 {
 {
     if (negative != other.negative)
     if (negative != other.negative)
         return addDigits(other);
         return addDigits(other);
@@ -474,7 +474,7 @@ TempDecimal & TempDecimal::subtract(const TempDecimal & other)
 }
 }
 
 
 
 
-TempDecimal & TempDecimal::subtractDigits(const TempDecimal & other)
+Decimal & Decimal::subtractDigits(const Decimal & other)
 {
 {
     extendRange(other);
     extendRange(other);
     byte oLo = other.lsb;
     byte oLo = other.lsb;
@@ -527,7 +527,7 @@ TempDecimal & TempDecimal::subtractDigits(const TempDecimal & other)
     return *this;
     return *this;
 }
 }
 
 
-TempDecimal & TempDecimal::truncate(int places)
+Decimal & Decimal::truncate(int places)
 {
 {
     //out of range - either 0 or overflow
     //out of range - either 0 or overflow
     if (places <= -maxIntegerDigits)
     if (places <= -maxIntegerDigits)
@@ -549,7 +549,7 @@ TempDecimal & TempDecimal::truncate(int places)
 }
 }
 
 
 
 
-size32_t TempDecimal::getStringLength() const
+size32_t Decimal::getStringLength() const
 {
 {
     int lo, hi;
     int lo, hi;
     clip(lo, hi);
     clip(lo, hi);
@@ -567,7 +567,7 @@ size32_t TempDecimal::getStringLength() const
 }
 }
 
 
 
 
-void TempDecimal::getCString(size32_t length, char * buffer) const
+void Decimal::getCString(size32_t length, char * buffer) const
 {
 {
     unsigned len = getStringLength();
     unsigned len = getStringLength();
     if (len >= length)
     if (len >= length)
@@ -582,7 +582,7 @@ void TempDecimal::getCString(size32_t length, char * buffer) const
     buffer[len] = 0;
     buffer[len] = 0;
 }
 }
 
 
-char * TempDecimal::getCString() const
+char * Decimal::getCString() const
 {
 {
     unsigned len = getStringLength();
     unsigned len = getStringLength();
     char * buffer = (char *)malloc(len+1);
     char * buffer = (char *)malloc(len+1);
@@ -593,7 +593,7 @@ char * TempDecimal::getCString() const
 }
 }
 
 
 
 
-void TempDecimal::getDecimal(byte length, byte precision, void * buffer, byte signs) const
+void Decimal::getDecimal(byte length, byte precision, void * buffer, byte signs) const
 {
 {
     doGetDecimal(length, 2*length-1, precision, buffer);
     doGetDecimal(length, 2*length-1, precision, buffer);
     byte sign = negative ? (signs & 0x0f) : (signs >> 4);
     byte sign = negative ? (signs & 0x0f) : (signs >> 4);
@@ -601,7 +601,7 @@ void TempDecimal::getDecimal(byte length, byte precision, void * buffer, byte si
 }
 }
 
 
 
 
-__int64 TempDecimal::getInt64() const
+__int64 Decimal::getInt64() const
 {
 {
     unsigned __int64 value = getUInt64();
     unsigned __int64 value = getUInt64();
     if (negative)
     if (negative)
@@ -610,7 +610,7 @@ __int64 TempDecimal::getInt64() const
 }
 }
 
 
 
 
-int TempDecimal::getInt() const
+int Decimal::getInt() const
 {
 {
     unsigned int value = getUInt();
     unsigned int value = getUInt();
     if (negative)
     if (negative)
@@ -619,7 +619,7 @@ int TempDecimal::getInt() const
 }
 }
 
 
 
 
-double TempDecimal::getReal() const
+double Decimal::getReal() const
 {
 {
     int lo, hi;
     int lo, hi;
     clip(lo, hi);
     clip(lo, hi);
@@ -659,7 +659,7 @@ double TempDecimal::getReal() const
 }
 }
 
 
 
 
-void TempDecimal::getString(size32_t length, char * buffer) const
+void Decimal::getString(size32_t length, char * buffer) const
 {
 {
     unsigned len = getStringLength();
     unsigned len = getStringLength();
     if (len > length)
     if (len > length)
@@ -674,7 +674,7 @@ void TempDecimal::getString(size32_t length, char * buffer) const
 }
 }
 
 
 
 
-void TempDecimal::getStringX(size32_t & length, char * & buffer) const
+void Decimal::getStringX(size32_t & length, char * & buffer) const
 {
 {
     unsigned len = getStringLength();
     unsigned len = getStringLength();
     buffer = (char *)malloc(len);
     buffer = (char *)malloc(len);
@@ -684,13 +684,13 @@ void TempDecimal::getStringX(size32_t & length, char * & buffer) const
 }
 }
 
 
 
 
-void TempDecimal::getUDecimal(byte length, byte precision, void * buffer) const
+void Decimal::getUDecimal(byte length, byte precision, void * buffer) const
 {
 {
     doGetDecimal(length, 2*length, precision, buffer);
     doGetDecimal(length, 2*length, precision, buffer);
 }
 }
 
 
 
 
-unsigned int TempDecimal::getUInt() const
+unsigned int Decimal::getUInt() const
 {
 {
     const unsigned hi = msb;
     const unsigned hi = msb;
     unsigned int value = 0;
     unsigned int value = 0;
@@ -716,7 +716,7 @@ unsigned int TempDecimal::getUInt() const
 }
 }
 
 
 
 
-unsigned __int64 TempDecimal::getUInt64() const
+unsigned __int64 Decimal::getUInt64() const
 {
 {
     //MORE: This isn't the most efficient way of doing it - see num2str in jutil for some hints.
     //MORE: This isn't the most efficient way of doing it - see num2str in jutil for some hints.
     const unsigned hi = msb;
     const unsigned hi = msb;
@@ -743,17 +743,17 @@ unsigned __int64 TempDecimal::getUInt64() const
 }
 }
 
 
 
 
-void TempDecimal::overflow()
+void Decimal::overflow()
 {
 {
 }
 }
 
 
 
 
-void TempDecimal::set(const TempDecimal & value)
+void Decimal::set(const Decimal & value)
 {
 {
     memcpy(this, &value, sizeof(*this));
     memcpy(this, &value, sizeof(*this));
 }
 }
 
 
-void TempDecimal::setCString(const char * buffer)
+void Decimal::setCString(const char * buffer)
 {
 {
     const char * cur = buffer;
     const char * cur = buffer;
     while (*cur == ' ')
     while (*cur == ' ')
@@ -798,7 +798,7 @@ void TempDecimal::setCString(const char * buffer)
 }
 }
 
 
 
 
-void TempDecimal::setDecimal(byte length, byte precision, const void * _buffer)
+void Decimal::setDecimal(byte length, byte precision, const void * _buffer)
 {
 {
     const byte * buffer = (const byte *)_buffer;
     const byte * buffer = (const byte *)_buffer;
     lsb = zeroDigit - precision;
     lsb = zeroDigit - precision;
@@ -829,7 +829,7 @@ void TempDecimal::setDecimal(byte length, byte precision, const void * _buffer)
 }
 }
 
 
 
 
-void TempDecimal::setInt64(__int64 value)
+void Decimal::setInt64(__int64 value)
 {
 {
     if (value >= 0)
     if (value >= 0)
         setUInt64((unsigned __int64)value);
         setUInt64((unsigned __int64)value);
@@ -841,7 +841,7 @@ void TempDecimal::setInt64(__int64 value)
 }
 }
 
 
 
 
-void TempDecimal::setInt(int value)
+void Decimal::setInt(int value)
 {
 {
     if (value >= 0)
     if (value >= 0)
         setUInt((unsigned int)value);
         setUInt((unsigned int)value);
@@ -852,7 +852,7 @@ void TempDecimal::setInt(int value)
     }
     }
 }
 }
 
 
-void TempDecimal::setReal(double value)
+void Decimal::setReal(double value)
 {
 {
     setZero();
     setZero();
 
 
@@ -906,7 +906,7 @@ void TempDecimal::setReal(double value)
 }
 }
 
 
 
 
-void TempDecimal::setString(size32_t length, const char * buffer)
+void Decimal::setString(size32_t length, const char * buffer)
 {
 {
     const char * limit = buffer+length;
     const char * limit = buffer+length;
     const char * cur = buffer;
     const char * cur = buffer;
@@ -953,7 +953,7 @@ void TempDecimal::setString(size32_t length, const char * buffer)
 }
 }
 
 
 
 
-void TempDecimal::setUInt(unsigned int value)
+void Decimal::setUInt(unsigned int value)
 {
 {
     negative = false;
     negative = false;
     lsb = zeroDigit;
     lsb = zeroDigit;
@@ -969,7 +969,7 @@ void TempDecimal::setUInt(unsigned int value)
 }
 }
 
 
 
 
-void TempDecimal::setUInt64(unsigned __int64 value)
+void Decimal::setUInt64(unsigned __int64 value)
 {
 {
     negative = false;
     negative = false;
     //MORE: This isn't the most efficient way of doing it - see num2str in jutil for some hints.
     //MORE: This isn't the most efficient way of doing it - see num2str in jutil for some hints.
@@ -986,7 +986,7 @@ void TempDecimal::setUInt64(unsigned __int64 value)
 }
 }
 
 
 
 
-void TempDecimal::setUDecimal(byte length, byte precision, const void * _buffer)
+void Decimal::setUDecimal(byte length, byte precision, const void * _buffer)
 {
 {
     const byte * buffer = (const byte *)_buffer;
     const byte * buffer = (const byte *)_buffer;
     lsb = zeroDigit - precision;
     lsb = zeroDigit - precision;
@@ -1003,7 +1003,7 @@ void TempDecimal::setUDecimal(byte length, byte precision, const void * _buffer)
 
 
 //-- helper functions:
 //-- helper functions:
 
 
-void TempDecimal::clip(int & newLsb, int & newMsb) const
+void Decimal::clip(int & newLsb, int & newMsb) const
 {
 {
     int lo = lsb;
     int lo = lsb;
     int hi = msb;
     int hi = msb;
@@ -1015,7 +1015,7 @@ void TempDecimal::clip(int & newLsb, int & newMsb) const
     newMsb = hi;
     newMsb = hi;
 }
 }
 
 
-void TempDecimal::clip(int & newLsb, int & newMsb, unsigned minLsb, unsigned maxMsb) const
+void Decimal::clip(int & newLsb, int & newMsb, unsigned minLsb, unsigned maxMsb) const
 {
 {
     clip(newLsb, newMsb);
     clip(newLsb, newMsb);
     if (newLsb < (int)minLsb)
     if (newLsb < (int)minLsb)
@@ -1026,7 +1026,7 @@ void TempDecimal::clip(int & newLsb, int & newMsb, unsigned minLsb, unsigned max
         newMsb = newLsb-1;
         newMsb = newLsb-1;
 }
 }
 
 
-unsigned TempDecimal::doGetString(char * buffer) const
+unsigned Decimal::doGetString(char * buffer) const
 {
 {
     char * cur = buffer;
     char * cur = buffer;
     int lo, hi;
     int lo, hi;
@@ -1076,7 +1076,7 @@ unsigned TempDecimal::doGetString(char * buffer) const
 }
 }
 
 
 
 
-void TempDecimal::doGetDecimal(byte length, byte maxDigits, byte precision, void * buffer) const
+void Decimal::doGetDecimal(byte length, byte maxDigits, byte precision, void * buffer) const
 {
 {
     int tgtHighPos = zeroDigit+maxDigits-precision-1;
     int tgtHighPos = zeroDigit+maxDigits-precision-1;
     int tgtLowPos = tgtHighPos - length*2 + 1;
     int tgtLowPos = tgtHighPos - length*2 + 1;
@@ -1132,14 +1132,14 @@ void TempDecimal::doGetDecimal(byte length, byte maxDigits, byte precision, void
     }
     }
 }
 }
 
 
-void TempDecimal::doPower(unsigned value)
+void Decimal::doPower(unsigned value)
 {
 {
     if (value == 1)
     if (value == 1)
         return;
         return;
 
 
     if (value & 1)
     if (value & 1)
     {
     {
-        TempDecimal saved(*this);
+        Decimal saved(*this);
         doPower(value >> 1);
         doPower(value >> 1);
         multiply(*this);
         multiply(*this);
         multiply(saved);
         multiply(saved);
@@ -1151,7 +1151,7 @@ void TempDecimal::doPower(unsigned value)
     }
     }
 }
 }
 
 
-void TempDecimal::setZero()
+void Decimal::setZero()
 {
 {
     negative = false;
     negative = false;
     lsb = msb = zeroDigit;
     lsb = msb = zeroDigit;

+ 49 - 49
rtl/nbcd/nbcd.hpp

@@ -47,27 +47,27 @@ template <byte length, byte precision> class decimal;
  * This class is notably used in the Decimal run-time library
  * This class is notably used in the Decimal run-time library
  * (nbcds.cpp), providing decimal arithmetic to ECL programs.
  * (nbcds.cpp), providing decimal arithmetic to ECL programs.
  */
  */
-class nbcd_decl TempDecimal
+class nbcd_decl Decimal
 {
 {
 public:
 public:
-    TempDecimal() { setZero(); }
-    TempDecimal(const TempDecimal & other);
+    Decimal() { setZero(); }
+    Decimal(const Decimal & other);
 
 
-    TempDecimal & abs();
-    TempDecimal & add(const TempDecimal & other);
+    Decimal & abs();
+    Decimal & add(const Decimal & other);
     int compareNull() const;
     int compareNull() const;
-    int compare(const TempDecimal & other) const;
-    TempDecimal & divide(const TempDecimal & other);
-    TempDecimal & modulus(const TempDecimal & other);
-    TempDecimal & multiply(const TempDecimal & other);
-    TempDecimal & negate();
-    TempDecimal & power(int value);
-    TempDecimal & power(unsigned value);
-    TempDecimal & round(int places=0);      // -ve means left of decimal point e.g., -3 = to nearest 1000.
-    TempDecimal & roundup(int places=0);        // -ve means left of decimal point e.g., -3 = to nearest 1000.
-    TempDecimal & setPrecision(byte numDigits, byte precision);
-    TempDecimal & subtract(const TempDecimal & other);
-    TempDecimal & truncate(int places=0);
+    int compare(const Decimal & other) const;
+    Decimal & divide(const Decimal & other);
+    Decimal & modulus(const Decimal & other);
+    Decimal & multiply(const Decimal & other);
+    Decimal & negate();
+    Decimal & power(int value);
+    Decimal & power(unsigned value);
+    Decimal & round(int places=0);      // -ve means left of decimal point e.g., -3 = to nearest 1000.
+    Decimal & roundup(int places=0);        // -ve means left of decimal point e.g., -3 = to nearest 1000.
+    Decimal & setPrecision(byte numDigits, byte precision);
+    Decimal & subtract(const Decimal & other);
+    Decimal & truncate(int places=0);
 
 
     size32_t getStringLength() const;
     size32_t getStringLength() const;
     void getCString(size32_t length, char * buffer) const;
     void getCString(size32_t length, char * buffer) const;
@@ -85,7 +85,7 @@ public:
     void getClipPrecision(unsigned & digits, unsigned & precision);
     void getClipPrecision(unsigned & digits, unsigned & precision);
     void getPrecision(unsigned & digits, unsigned & precison);
     void getPrecision(unsigned & digits, unsigned & precison);
 
 
-    void set(const TempDecimal & value);
+    void set(const Decimal & value);
     void setCString(const char * buffer);
     void setCString(const char * buffer);
     void setDecimal(byte length, byte precision, const void * buffer);
     void setDecimal(byte length, byte precision, const void * buffer);
     void setInt64(__int64 value);
     void setInt64(__int64 value);
@@ -99,25 +99,25 @@ public:
 
 
 #ifdef DECIMAL_OVERLOAD
 #ifdef DECIMAL_OVERLOAD
     template <byte length, byte precision> 
     template <byte length, byte precision> 
-    TempDecimal(const decimal<length, precision> & x)   { setDecimal(length, precision, &x); }
-    inline TempDecimal(int value)                               { setInt(value); }
-    inline TempDecimal(unsigned value)                          { setUInt(value); }
-    inline TempDecimal(__int64 value)                           { setInt64(value); }
-    inline TempDecimal(unsigned __int64 value)                  { setUInt64(value); }
-    inline TempDecimal(double value)                            { setReal(value); }
-    inline TempDecimal(const char * value)                      { setCString(value); }
-
-    inline TempDecimal & operator = (int value)                 { setInt(value); return *this; }
-    inline TempDecimal & operator = (unsigned value)            { setUInt(value); return *this; }
-    inline TempDecimal & operator = (__int64 value)             { setInt64(value); return *this; }
-    inline TempDecimal & operator = (unsigned __int64 value)    { setUInt64(value); return *this; }
-    inline TempDecimal & operator = (double value)              { setReal(value); return *this; }
-    inline TempDecimal & operator = (const char * value)        { setCString(value); return *this; }
+    Decimal(const decimal<length, precision> & x)   { setDecimal(length, precision, &x); }
+    inline Decimal(int value)                               { setInt(value); }
+    inline Decimal(unsigned value)                          { setUInt(value); }
+    inline Decimal(__int64 value)                           { setInt64(value); }
+    inline Decimal(unsigned __int64 value)                  { setUInt64(value); }
+    inline Decimal(double value)                            { setReal(value); }
+    inline Decimal(const char * value)                      { setCString(value); }
+
+    inline Decimal & operator = (int value)                 { setInt(value); return *this; }
+    inline Decimal & operator = (unsigned value)            { setUInt(value); return *this; }
+    inline Decimal & operator = (__int64 value)             { setInt64(value); return *this; }
+    inline Decimal & operator = (unsigned __int64 value)    { setUInt64(value); return *this; }
+    inline Decimal & operator = (double value)              { setReal(value); return *this; }
+    inline Decimal & operator = (const char * value)        { setCString(value); return *this; }
 #endif
 #endif
 
 
 protected:
 protected:
-    TempDecimal & addDigits(const TempDecimal & other);
-    TempDecimal & subtractDigits(const TempDecimal & other);
+    Decimal & addDigits(const Decimal & other);
+    Decimal & subtractDigits(const Decimal & other);
     void clip(int & newLsb, int & newMsb) const;
     void clip(int & newLsb, int & newMsb) const;
     void clip(int & newLsb, int & newMsb, unsigned minLsb, unsigned maxMsb) const;
     void clip(int & newLsb, int & newMsb, unsigned minLsb, unsigned maxMsb) const;
     void doGetDecimal(byte length, byte maxDigits, byte precision, void * buffer) const;
     void doGetDecimal(byte length, byte maxDigits, byte precision, void * buffer) const;
@@ -125,11 +125,11 @@ protected:
 
 
     unsigned doGetString(char * target) const;
     unsigned doGetString(char * target) const;
     void extendRange(byte oLsb, byte oMsb);
     void extendRange(byte oLsb, byte oMsb);
-    void extendRange(const TempDecimal & other)     { extendRange(other.lsb, other.msb); }
+    void extendRange(const Decimal & other)     { extendRange(other.lsb, other.msb); }
     void overflow();
     void overflow();
 
 
 private:
 private:
-    TempDecimal & incLSD();
+    Decimal & incLSD();
 
 
 protected:
 protected:
     enum { 
     enum { 
@@ -151,7 +151,7 @@ class decimal
 {
 {
 public:
 public:
     decimal()                               { memset(buffer, 0, length); }
     decimal()                               { memset(buffer, 0, length); }
-    decimal(const TempDecimal & other)      { other.getDecimal(length, precision, buffer); }
+    decimal(const Decimal & other)      { other.getDecimal(length, precision, buffer); }
 
 
 protected:
 protected:
     byte buffer[length];
     byte buffer[length];
@@ -162,24 +162,24 @@ class udecimal
 {
 {
 public:
 public:
     udecimal()                              { memset(buffer, 0, length); }
     udecimal()                              { memset(buffer, 0, length); }
-    udecimal(const TempDecimal & other)     { other.getUDecimal(length, precision, buffer); }
+    udecimal(const Decimal & other)     { other.getUDecimal(length, precision, buffer); }
 
 
 protected:
 protected:
     byte buffer[length];
     byte buffer[length];
 };
 };
 
 
 #ifdef DECIMAL_OVERLOAD
 #ifdef DECIMAL_OVERLOAD
-inline TempDecimal operator + (const TempDecimal & left, const TempDecimal & right) { return TempDecimal(left).add(right); }
-inline TempDecimal operator - (const TempDecimal & left, const TempDecimal & right) { return TempDecimal(left).subtract(right); }
-inline TempDecimal operator * (const TempDecimal & left, const TempDecimal & right) { return TempDecimal(left).multiply(right); }
-inline TempDecimal operator / (const TempDecimal & left, const TempDecimal & right) { return TempDecimal(left).divide(right); }
-inline TempDecimal operator % (const TempDecimal & left, const TempDecimal & right) { return TempDecimal(left).modulus(right); }
-inline bool operator == (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) == 0; }
-inline bool operator != (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) != 0; }
-inline bool operator >= (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) >= 0; }
-inline bool operator <= (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) <= 0; }
-inline bool operator > (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) > 0; }
-inline bool operator < (const TempDecimal & left, const TempDecimal & right) { return left.compare(right) < 0; }
+inline Decimal operator + (const Decimal & left, const Decimal & right) { return Decimal(left).add(right); }
+inline Decimal operator - (const Decimal & left, const Decimal & right) { return Decimal(left).subtract(right); }
+inline Decimal operator * (const Decimal & left, const Decimal & right) { return Decimal(left).multiply(right); }
+inline Decimal operator / (const Decimal & left, const Decimal & right) { return Decimal(left).divide(right); }
+inline Decimal operator % (const Decimal & left, const Decimal & right) { return Decimal(left).modulus(right); }
+inline bool operator == (const Decimal & left, const Decimal & right) { return left.compare(right) == 0; }
+inline bool operator != (const Decimal & left, const Decimal & right) { return left.compare(right) != 0; }
+inline bool operator >= (const Decimal & left, const Decimal & right) { return left.compare(right) >= 0; }
+inline bool operator <= (const Decimal & left, const Decimal & right) { return left.compare(right) <= 0; }
+inline bool operator > (const Decimal & left, const Decimal & right) { return left.compare(right) > 0; }
+inline bool operator < (const Decimal & left, const Decimal & right) { return left.compare(right) < 0; }
 #endif
 #endif
 
 
 bool dec2Bool(size32_t bytes, const void * data);
 bool dec2Bool(size32_t bytes, const void * data);

+ 5 - 5
rtl/nbcd/nbcds.cpp

@@ -35,7 +35,7 @@ nbcd_decl void _fastcall  DecUnlock()
     bcdCriticalSection.leave();
     bcdCriticalSection.leave();
 }
 }
 
 
-static TempDecimal stack[32];
+static Decimal stack[32];
 unsigned  curStack;
 unsigned  curStack;
 
 
 
 
@@ -253,10 +253,10 @@ nbcd_decl void _fastcall  DecRoundTo(unsigned places)
 
 
 nbcd_decl void _fastcall  DecSwap()
 nbcd_decl void _fastcall  DecSwap()
 {
 {
-    char temp[sizeof(TempDecimal)];
-    memcpy(&temp, &stack[curStack-1], sizeof(TempDecimal));
-    memcpy(&stack[curStack-1], &stack[curStack-2], sizeof(TempDecimal));
-    memcpy(&stack[curStack-2], &temp, sizeof(TempDecimal));
+    char temp[sizeof(Decimal)];
+    memcpy(&temp, &stack[curStack-1], sizeof(Decimal));
+    memcpy(&stack[curStack-1], &stack[curStack-2], sizeof(Decimal));
+    memcpy(&stack[curStack-2], &temp, sizeof(Decimal));
 }
 }
 
 
 
 

+ 44 - 44
rtl/nbcd/nbcdtest.cpp

@@ -92,8 +92,8 @@ protected:
     {
     {
         if (!right) right = left;
         if (!right) right = left;
         char temp[80];
         char temp[80];
-        TempDecimal a = left;
-        TempDecimal b = right;
+        Decimal a = left;
+        Decimal b = right;
         a.multiply(b);
         a.multiply(b);
         a.getCString(sizeof(temp), temp);
         a.getCString(sizeof(temp), temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testMultiply/getCString: expected '%s', got '%s'", expected, temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testMultiply/getCString: expected '%s', got '%s'", expected, temp);
@@ -107,8 +107,8 @@ protected:
     void testDivide(const char * left, const char * right, const char * expected)
     void testDivide(const char * left, const char * right, const char * expected)
     {
     {
         char temp[80];
         char temp[80];
-        TempDecimal a = left;
-        TempDecimal b = right;
+        Decimal a = left;
+        Decimal b = right;
         a.divide(b);
         a.divide(b);
         a.getCString(sizeof(temp), temp);
         a.getCString(sizeof(temp), temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testDivide/getCString: expected '%s', got '%s'", expected, temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testDivide/getCString: expected '%s', got '%s'", expected, temp);
@@ -121,8 +121,8 @@ protected:
 
 
     void testCompare(const char * left, const char * right, int expected)
     void testCompare(const char * left, const char * right, int expected)
     {
     {
-        TempDecimal a = left;
-        TempDecimal b = right;
+        Decimal a = left;
+        Decimal b = right;
         int temp = a.compare(b);
         int temp = a.compare(b);
         cppunit_assert(temp == expected, "ERROR: testCompare/positive: expected '%d', got '%d'", expected, temp);
         cppunit_assert(temp == expected, "ERROR: testCompare/positive: expected '%d', got '%d'", expected, temp);
         temp = b.compare(a);
         temp = b.compare(a);
@@ -137,27 +137,27 @@ protected:
     void testModulus(const char * left, const char * right, const char * expected)
     void testModulus(const char * left, const char * right, const char * expected)
     {
     {
         char temp[80];
         char temp[80];
-        TempDecimal a = left;
-        TempDecimal b = right;
+        Decimal a = left;
+        Decimal b = right;
         a.modulus(b);
         a.modulus(b);
         a.getCString(sizeof(temp), temp);
         a.getCString(sizeof(temp), temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testModulus: expected '%s', got '%s'", expected, temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: testModulus: expected '%s', got '%s'", expected, temp);
     }
     }
 
 
-    void checkDecimal(const TempDecimal & value, const char * expected)
+    void checkDecimal(const Decimal & value, const char * expected)
     {
     {
         char temp[80];
         char temp[80];
         value.getCString(sizeof(temp), temp);
         value.getCString(sizeof(temp), temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: checkDecimal/char: expected '%s', got '%s'", expected, temp);
         cppunit_assert(strcmp(expected, temp) == 0, "ERROR: checkDecimal/char: expected '%s', got '%s'", expected, temp);
     }
     }
 
 
-    void checkDecimal(const TempDecimal & value, unsigned __int64 expected)
+    void checkDecimal(const Decimal & value, unsigned __int64 expected)
     {
     {
         unsigned __int64 temp = value.getUInt64();
         unsigned __int64 temp = value.getUInt64();
         cppunit_assert(expected == temp, "ERROR: checkDecimal/uint64: expected '%" I64F "d', got '%" I64F "d'", expected, temp);
         cppunit_assert(expected == temp, "ERROR: checkDecimal/uint64: expected '%" I64F "d', got '%" I64F "d'", expected, temp);
     }
     }
 
 
-    void checkDecimal(const TempDecimal & value, __int64 expected)
+    void checkDecimal(const Decimal & value, __int64 expected)
     {
     {
         __int64 temp = value.getInt64();
         __int64 temp = value.getInt64();
         cppunit_assert(expected == temp, "ERROR: checkDecimal/int64: expected '%" I64F "d', got '%" I64F "d'", expected, temp);
         cppunit_assert(expected == temp, "ERROR: checkDecimal/int64: expected '%" I64F "d', got '%" I64F "d'", expected, temp);
@@ -183,10 +183,10 @@ protected:
 
 
             for (int i = 0; i < 2; i++)
             for (int i = 0; i < 2; i++)
             {
             {
-                TempDecimal d1 = val1;
-                TempDecimal d2 = val2;
-                TempDecimal d3 = val3;
-                TempDecimal d4 = val4;
+                Decimal d1 = val1;
+                Decimal d2 = val2;
+                Decimal d3 = val3;
+                Decimal d4 = val4;
 
 
                 d1.multiply(d2);
                 d1.multiply(d2);
                 d3.multiply(d4);
                 d3.multiply(d4);
@@ -204,7 +204,7 @@ protected:
     void testBcdUninitialized()
     void testBcdUninitialized()
     {
     {
         // Test uninitialised
         // Test uninitialised
-        TempDecimal zero, one=1, two(2);
+        Decimal zero, one=1, two(2);
         checkDecimal(zero, 0ULL);
         checkDecimal(zero, 0ULL);
         checkDecimal(one, 1ULL);
         checkDecimal(one, 1ULL);
         checkDecimal(two, 2ULL);
         checkDecimal(two, 2ULL);
@@ -216,7 +216,7 @@ protected:
 
 
     void testBcdCString()
     void testBcdCString()
     {
     {
-        TempDecimal a,b,c;
+        Decimal a,b,c;
         a.setString(10,"1234.56789");   // 1234.56789
         a.setString(10,"1234.56789");   // 1234.56789
         b.setString(8,"  123456.88");   // 123456
         b.setString(8,"  123456.88");   // 123456
         c.setString(6," 0.123 ");
         c.setString(6," 0.123 ");
@@ -240,7 +240,7 @@ protected:
     void testBcdRoundTruncate()
     void testBcdRoundTruncate()
     {
     {
         char temp[80];
         char temp[80];
-        TempDecimal c = "9.53456";
+        Decimal c = "9.53456";
         checkDecimal(c, "9.53456");
         checkDecimal(c, "9.53456");
         c.round(4);
         c.round(4);
         checkDecimal(c,"9.5346");
         checkDecimal(c,"9.5346");
@@ -266,37 +266,37 @@ protected:
         c.truncate();
         c.truncate();
         checkDecimal(c, "9");
         checkDecimal(c, "9");
 
 
-        TempDecimal x1 = 1;
+        Decimal x1 = 1;
         x1.round(-3);
         x1.round(-3);
         checkDecimal(x1, (__int64)0);
         checkDecimal(x1, (__int64)0);
-        TempDecimal x2 = 100;
+        Decimal x2 = 100;
         x2.round(-3);
         x2.round(-3);
         checkDecimal(x2, (__int64)0);
         checkDecimal(x2, (__int64)0);
-        TempDecimal x3 = 499;
+        Decimal x3 = 499;
         x3.round(-3);
         x3.round(-3);
         checkDecimal(x3, (__int64)0);
         checkDecimal(x3, (__int64)0);
-        TempDecimal x4 = 500;
+        Decimal x4 = 500;
         x4.round(-3);
         x4.round(-3);
         checkDecimal(x4, (__int64)1000);
         checkDecimal(x4, (__int64)1000);
-        TempDecimal x5 = 1000;
+        Decimal x5 = 1000;
         x5.round(-3);
         x5.round(-3);
         checkDecimal(x5, (__int64)1000);
         checkDecimal(x5, (__int64)1000);
-        TempDecimal x6 = 1499;
+        Decimal x6 = 1499;
         x6.round(-3);
         x6.round(-3);
         checkDecimal(x6, (__int64)1000);
         checkDecimal(x6, (__int64)1000);
-        TempDecimal x7 = 1500;
+        Decimal x7 = 1500;
         x7.round(-3);
         x7.round(-3);
         checkDecimal(x7, (__int64)2000);
         checkDecimal(x7, (__int64)2000);
-        TempDecimal x8 = 10000;
+        Decimal x8 = 10000;
         x8.round(-3);
         x8.round(-3);
         checkDecimal(x8, (__int64)10000);
         checkDecimal(x8, (__int64)10000);
-        TempDecimal x9 = 10499;
+        Decimal x9 = 10499;
         x9.round(-3);
         x9.round(-3);
         checkDecimal(x9, (__int64)10000);
         checkDecimal(x9, (__int64)10000);
-        TempDecimal x10 = 10500;
+        Decimal x10 = 10500;
         x10.round(-3);
         x10.round(-3);
         checkDecimal(x10, (__int64)11000);
         checkDecimal(x10, (__int64)11000);
-        TempDecimal x11 = -10500;
+        Decimal x11 = -10500;
         x11.round(-3);
         x11.round(-3);
         checkDecimal(x11, (__int64)-11000);
         checkDecimal(x11, (__int64)-11000);
 
 
@@ -308,7 +308,7 @@ protected:
 
 
     void testBcdDecimal()
     void testBcdDecimal()
     {
     {
-        TempDecimal a = "123.2345";
+        Decimal a = "123.2345";
         unsigned decBufferSize=5;
         unsigned decBufferSize=5;
         char decBuffer[7];
         char decBuffer[7];
         char * decBufferPtr = decBuffer+1;
         char * decBufferPtr = decBuffer+1;
@@ -395,7 +395,7 @@ protected:
 
 
     void testBcdInt()
     void testBcdInt()
     {
     {
-        TempDecimal a, b;
+        Decimal a, b;
         for (unsigned i1 = 0; i1 <= 1000; i1++)
         for (unsigned i1 = 0; i1 <= 1000; i1++)
         {
         {
             a = i1;
             a = i1;
@@ -411,8 +411,8 @@ protected:
 
 
         for (unsigned i2 = 0; i2 <= 100; i2++)
         for (unsigned i2 = 0; i2 <= 100; i2++)
         {
         {
-            TempDecimal x = i2;
-            TempDecimal y = 100;
+            Decimal x = i2;
+            Decimal y = 100;
             y.multiply(x);
             y.multiply(x);
             cppunit_assert(100*i2 == (unsigned)y.getInt(), "ERROR: testBcdInt/getInt*100: expected '%d', got '%d'", 100*i2, y.getInt());
             cppunit_assert(100*i2 == (unsigned)y.getInt(), "ERROR: testBcdInt/getInt*100: expected '%d', got '%d'", 100*i2, y.getInt());
             x.multiply(x);
             x.multiply(x);
@@ -442,8 +442,8 @@ protected:
         testMultiply("0.000000000000000101","0.000000000000000099009901","0.00000000000000000000000000000001");
         testMultiply("0.000000000000000101","0.000000000000000099009901","0.00000000000000000000000000000001");
         testMultiply("109", "9174311926605504587155963302.75229357798165137614678899082568", "999999999999999999999999999999.99999999999999999999999999999912");
         testMultiply("109", "9174311926605504587155963302.75229357798165137614678899082568", "999999999999999999999999999999.99999999999999999999999999999912");
 
 
-        TempDecimal a = "9999999999999999";
-        TempDecimal b = "10000000000000002";
+        Decimal a = "9999999999999999";
+        Decimal b = "10000000000000002";
         char temp[80];
         char temp[80];
         a.multiply(b);
         a.multiply(b);
         a.getCString(sizeof(temp), temp);
         a.getCString(sizeof(temp), temp);
@@ -502,25 +502,25 @@ protected:
     {
     {
         //MORE: Test power functions...
         //MORE: Test power functions...
         const char * values[] = { "0.00001", "10000", "-1", "-10", "1.0001", "9.99" };
         const char * values[] = { "0.00001", "10000", "-1", "-10", "1.0001", "9.99" };
-        TempDecimal one(1);
+        Decimal one(1);
         for (unsigned idx = 0; idx < _elements_in(values); idx++)
         for (unsigned idx = 0; idx < _elements_in(values); idx++)
         {
         {
-            TempDecimal value = values[idx];
-            TempDecimal sofar1 = 1;
-            TempDecimal sofar2 = 1;
+            Decimal value = values[idx];
+            Decimal sofar1 = 1;
+            Decimal sofar2 = 1;
 
 
             bool success=true;
             bool success=true;
             for (int power = 0; power < 10; power++)
             for (int power = 0; power < 10; power++)
             {
             {
-                TempDecimal powerValue1 = values[idx];
-                TempDecimal powerValue2 = values[idx];
+                Decimal powerValue1 = values[idx];
+                Decimal powerValue2 = values[idx];
                 powerValue1.power(power);
                 powerValue1.power(power);
                 powerValue2.power(-power);
                 powerValue2.power(-power);
 
 
                 char temp1[80], temp2[80], temp3[80];
                 char temp1[80], temp2[80], temp3[80];
                 if (sofar1.compare(powerValue1) != 0)
                 if (sofar1.compare(powerValue1) != 0)
                 {
                 {
-                    TempDecimal diff = powerValue1;
+                    Decimal diff = powerValue1;
                     diff.subtract(sofar1);
                     diff.subtract(sofar1);
                     sofar1.getCString(sizeof(temp1), temp1);
                     sofar1.getCString(sizeof(temp1), temp1);
                     powerValue1.getCString(sizeof(temp2), temp2);
                     powerValue1.getCString(sizeof(temp2), temp2);
@@ -529,7 +529,7 @@ protected:
                 }
                 }
                 if (sofar2.compare(powerValue2) != 0)
                 if (sofar2.compare(powerValue2) != 0)
                 {
                 {
-                    TempDecimal diff = powerValue2;
+                    Decimal diff = powerValue2;
                     diff.subtract(sofar2);
                     diff.subtract(sofar2);
                     sofar2.getCString(sizeof(temp1), temp1);
                     sofar2.getCString(sizeof(temp1), temp1);
                     powerValue2.getCString(sizeof(temp2), temp2);
                     powerValue2.getCString(sizeof(temp2), temp2);
@@ -543,7 +543,7 @@ protected:
                     powerValue1.multiply(powerValue2);
                     powerValue1.multiply(powerValue2);
                     if (power && (powerValue1.compareNull() != 0) && (powerValue1.compare(one) != 0))
                     if (power && (powerValue1.compareNull() != 0) && (powerValue1.compare(one) != 0))
                     {
                     {
-                        TempDecimal diff = powerValue1;
+                        Decimal diff = powerValue1;
                         diff.subtract(one);
                         diff.subtract(one);
                         one.getCString(sizeof(temp1), temp1);
                         one.getCString(sizeof(temp1), temp1);
                         powerValue1.getCString(sizeof(temp2), temp2);
                         powerValue1.getCString(sizeof(temp2), temp2);