peiyongz 2002/12/10 16:20:03
Modified: c/src/xercesc/util XMLFloat.hpp XMLFloat.cpp XMLDouble.hpp
XMLDouble.cpp XMLAbstractDoubleFloat.hpp
XMLAbstractDoubleFloat.cpp
Log:
Doing businesss in value space. Converting out-of-bound value into special values.
Revision Changes Path
1.4 +4 -7 xml-xerces/c/src/xercesc/util/XMLFloat.hpp
Index: XMLFloat.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLFloat.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLFloat.hpp 4 Nov 2002 15:22:05 -0000 1.3
+++ XMLFloat.hpp 11 Dec 2002 00:20:02 -0000 1.4
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.4 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.3 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -132,11 +135,6 @@
inline static int compareValues(const XMLFloat* const lValue
, const XMLFloat* const rValue);
- // -----------------------------------------------------------------------
- // Notification that lazy data has been deleted
- // -----------------------------------------------------------------------
- static void reinitXMLFloat();
-
protected:
void checkBoundary(const XMLCh* const strValue);
@@ -163,4 +161,3 @@
XERCES_CPP_NAMESPACE_END
#endif
-
1.5 +53 -159 xml-xerces/c/src/xercesc/util/XMLFloat.cpp
Index: XMLFloat.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLFloat.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLFloat.cpp 4 Nov 2002 15:22:05 -0000 1.4
+++ XMLFloat.cpp 11 Dec 2002 00:20:02 -0000 1.5
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.5 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.4 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -114,89 +117,16 @@
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLFloat.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-#include <xercesc/util/XMLRegisterCleanup.hpp>
#include <xercesc/util/XMLString.hpp>
-#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/NumberFormatException.hpp>
+#include <xercesc/util/Janitor.hpp>
-XERCES_CPP_NAMESPACE_BEGIN
-
-// ---------------------------------------------------------------------------
-// local data member
-// ---------------------------------------------------------------------------
-//
-// 2^24 x 2^104 = 2^128 = 3.4028236692093846346337460743177e+38
-// +
-// 3.4028 236692 093846 346337 460743 177
-// e+38
-//
-static const XMLCh FLT_MAX_POSITIVE[] =
-{
- chPlus,
- chDigit_3, chPeriod, chDigit_4, chDigit_0, chDigit_2, chDigit_8,
- chDigit_2, chDigit_3, chDigit_6, chDigit_6, chDigit_9, chDigit_2,
- chDigit_0, chDigit_9, chDigit_3, chDigit_8, chDigit_4, chDigit_6,
- chDigit_3, chDigit_4, chDigit_6, chDigit_3, chDigit_3, chDigit_7,
- chDigit_4, chDigit_6, chDigit_0, chDigit_7, chDigit_4, chDigit_3,
- chDigit_1, chDigit_7, chDigit_7,
- chLatin_E, chPlus, chDigit_3, chDigit_8, chNull
-};
-
-//
-// 2^0 x 2^-149 = 2^-149 = 1.4012984643248170709237295832899e-45
-// +
-// 1.4012 984643 248170 709237 295832 899
-// e-45
-//
-static const XMLCh FLT_MIN_POSITIVE[] =
-{
- chPlus,
- chDigit_1, chPeriod, chDigit_4, chDigit_0, chDigit_1, chDigit_2,
- chDigit_9, chDigit_8, chDigit_4, chDigit_6, chDigit_4, chDigit_3,
- chDigit_2, chDigit_4, chDigit_8, chDigit_1, chDigit_7, chDigit_0,
- chDigit_7, chDigit_0, chDigit_9, chDigit_2, chDigit_3, chDigit_7,
- chDigit_2, chDigit_9, chDigit_5, chDigit_8, chDigit_3, chDigit_2,
- chDigit_8, chDigit_9, chDigit_9,
- chLatin_E, chDash, chDigit_4, chDigit_5, chNull
-};
-
-static const XMLCh FLT_MAX_NEGATIVE[] =
-{
- chDash,
- chDigit_3, chPeriod, chDigit_4, chDigit_0, chDigit_2, chDigit_8,
- chDigit_2, chDigit_3, chDigit_6, chDigit_6, chDigit_9, chDigit_2,
- chDigit_0, chDigit_9, chDigit_3, chDigit_8, chDigit_4, chDigit_6,
- chDigit_3, chDigit_4, chDigit_6, chDigit_3, chDigit_3, chDigit_7,
- chDigit_4, chDigit_6, chDigit_0, chDigit_7, chDigit_4, chDigit_3,
- chDigit_1, chDigit_7, chDigit_7,
- chLatin_E, chPlus, chDigit_3, chDigit_8, chNull
-};
-
-static const XMLCh FLT_MIN_NEGATIVE[] =
-{
- chDash,
- chDigit_1, chPeriod, chDigit_4, chDigit_0, chDigit_1, chDigit_2,
- chDigit_9, chDigit_8, chDigit_4, chDigit_6, chDigit_4, chDigit_3,
- chDigit_2, chDigit_4, chDigit_8, chDigit_1, chDigit_7, chDigit_0,
- chDigit_7, chDigit_0, chDigit_9, chDigit_2, chDigit_3, chDigit_7,
- chDigit_2, chDigit_9, chDigit_5, chDigit_8, chDigit_3, chDigit_2,
- chDigit_8, chDigit_9, chDigit_9,
- chLatin_E, chDash, chDigit_4, chDigit_5, chNull
-};
-
-//
-// maxNegativeValue < minNegativeValue < 0 < minPositiveValue < maxPositiveValue
-// They are all "Inclusive value"
-//
-
-static XMLFloat* maxNegativeValue = 0;
-static XMLFloat* minNegativeValue = 0;
-static XMLFloat* minPositiveValue = 0;
-static XMLFloat* maxPositiveValue = 0;
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <float.h>
-static XMLMutex* sFloatMutex = 0;
-static XMLRegisterCleanup XMLFloatCleanup;
+XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// ctor/dtor
@@ -211,95 +141,59 @@
{
}
-//
-//
void XMLFloat::checkBoundary(const XMLCh* const strValue)
{
- if (!sFloatMutex)
- {
- XMLMutex* tmpMutex = new XMLMutex;
- if (XMLPlatformUtils::compareAndSwap((void**)&sFloatMutex, tmpMutex, 0))
- {
- // Some other thread beat us to it, so let's clean up ours.
- delete tmpMutex;
- }
- else
- {
- //
- // the thread who creates the mutex succesfully, to
- // initialize the followings
- //
- maxNegativeValue = new XMLFloat(FLT_MAX_NEGATIVE);
- minNegativeValue = new XMLFloat(FLT_MIN_NEGATIVE);
- minPositiveValue = new XMLFloat(FLT_MIN_POSITIVE);
- maxPositiveValue = new XMLFloat(FLT_MAX_POSITIVE);
+ char *nptr = XMLString::transcode(strValue);
+ ArrayJanitor<char> jan1(nptr);
+ int strLen = strlen(nptr);
+ char *endptr = 0;
+ errno = 0;
+ fValue = strtod(nptr, &endptr);
- // This is the real mutex. Register it for cleanup at Termination.
- XMLFloatCleanup.registerCleanup(reinitXMLFloat);
- }
- }
-
- //
- // by-pass boundary check for boundary value itself
- //
- if ((XMLString::equals(strValue, FLT_MAX_NEGATIVE)) ||
- (XMLString::equals(strValue, FLT_MIN_NEGATIVE)) ||
- (XMLString::equals(strValue, FLT_MIN_POSITIVE)) ||
- (XMLString::equals(strValue, FLT_MAX_POSITIVE)) )
- return;
-
- // error: this < maxNegativeValue
- if ( compareValues(this, maxNegativeValue) == -1 )
+ // check if all chars are valid char
+ if ( (endptr - nptr) != strLen)
{
- ThrowXML2(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_maxNeg
- , strValue
- , FLT_MAX_NEGATIVE);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars);
}
- // error: this > maxPositiveValue
- if ( compareValues(this, maxPositiveValue) == 1 )
+ // check if overflow/underflow occurs
+ if (errno == ERANGE)
{
- ThrowXML2(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_maxPos
- , strValue
- , FLT_MAX_POSITIVE);
+ if ( fValue < 0 )
+ {
+ fType = NegINF;
+ }
+ else if ( fValue > 0)
+ {
+ fType = PosINF;
+ }
+ else
+ {
+ fType = (getSign() == 1) ? PosZero : NegZero;
+ }
}
-
- // error: minNegativeValue < this < minPositiveValue
- // value is not be representable
- if (( compareValues(this, minNegativeValue) == 1 ) &&
- ( compareValues(this, minPositiveValue) == -1 ) )
+ else
{
- ThrowXML3(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_minNegPos
- , strValue
- , FLT_MIN_NEGATIVE
- , FLT_MIN_POSITIVE);
+ /**
+ * float related checking
+ */
+ if (fValue < (-1) * FLT_MAX)
+ {
+ fType = NegINF;
+ }
+ else if (fValue > (-1)*FLT_MIN && fValue < 0)
+ {
+ fValue = 0;
+ }
+ else if (fValue > 0 && fValue < FLT_MIN )
+ {
+ fValue = 0;
+ }
+ else if (fValue > FLT_MAX)
+ {
+ fType = PosINF;
+ }
}
-
-}
-
-// -----------------------------------------------------------------------
-// Notification that lazy data has been deleted
-// -----------------------------------------------------------------------
-void XMLFloat::reinitXMLFloat() {
-
- delete sFloatMutex;
- sFloatMutex = 0;
-
- delete maxNegativeValue;
- maxNegativeValue = 0;
-
- delete minNegativeValue;
- minNegativeValue = 0;
-
- delete minPositiveValue;
- minPositiveValue = 0;
-
- delete maxPositiveValue;
- maxPositiveValue = 0;
-
}
XERCES_CPP_NAMESPACE_END
1.4 +4 -6 xml-xerces/c/src/xercesc/util/XMLDouble.hpp
Index: XMLDouble.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLDouble.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLDouble.hpp 4 Nov 2002 15:22:05 -0000 1.3
+++ XMLDouble.hpp 11 Dec 2002 00:20:02 -0000 1.4
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.4 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.3 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -137,11 +140,6 @@
inline static int compareValues(const XMLDouble* const lValue
, const XMLDouble* const rValue);
-
- // -----------------------------------------------------------------------
- // Notification that lazy data has been deleted
- // -----------------------------------------------------------------------
- static void reinitXMLDouble();
protected:
1.5 +33 -177 xml-xerces/c/src/xercesc/util/XMLDouble.cpp
Index: XMLDouble.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLDouble.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLDouble.cpp 4 Nov 2002 15:22:05 -0000 1.4
+++ XMLDouble.cpp 11 Dec 2002 00:20:02 -0000 1.5
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.5 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.4 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -122,107 +125,16 @@
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLDouble.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-#include <xercesc/util/XMLRegisterCleanup.hpp>
#include <xercesc/util/XMLString.hpp>
-#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/NumberFormatException.hpp>
+#include <xercesc/util/Janitor.hpp>
-XERCES_CPP_NAMESPACE_BEGIN
-
-//---------
-// TODO:
-//
-// Double is supposed to hold 64 bit number and currently
-// we have implemented the checking on boundary values, such
-// the maximum/minimum positive/negative number.
-//
-// We also need to do roundup/roundoff for extra bit in the
-// lexical representation.
-// In order to do that, we need to store them in a canonical form,
-// like this.
-// [-]?[1-9].[0-9]+[E|e][-]?[0-9]+
-//
-// Then we can impose the limit of length after the '.' before 'E'.
-//
-//---------
-
-// ---------------------------------------------------------------------------
-// local data member
-// ---------------------------------------------------------------------------
-
-//
-// 2^53 x 2^970 = 2^1023 = 8.9884656743115795386465259539451e+307
-// +
-// 8.9884 656743 115795 386465 259539 451
-// e+307
-//
-static const XMLCh DBL_MAX_POSITIVE[] =
-{
- chPlus,
- chDigit_8, chPeriod, chDigit_9, chDigit_8, chDigit_8, chDigit_4,
- chDigit_6, chDigit_5, chDigit_6, chDigit_7, chDigit_4, chDigit_3,
- chDigit_1, chDigit_1, chDigit_5, chDigit_7, chDigit_9, chDigit_5,
- chDigit_3, chDigit_8, chDigit_6, chDigit_4, chDigit_6, chDigit_5,
- chDigit_2, chDigit_5, chDigit_9, chDigit_5, chDigit_3, chDigit_9,
- chDigit_4, chDigit_5, chDigit_1,
- chLatin_E, chPlus, chDigit_3, chDigit_0, chDigit_7, chNull
-};
-
-//
-// 2^0 x 2^-1075 = 2^-1075 = 2.4703282292062327208828439643411e-324
-// +
-// 2.4703 282292 062327 208828 439643 411
-// e-324
-//
-static const XMLCh DBL_MIN_POSITIVE[] =
-{
- chPlus,
- chDigit_2, chPeriod, chDigit_4, chDigit_7, chDigit_0, chDigit_3,
- chDigit_2, chDigit_8, chDigit_2, chDigit_2, chDigit_9, chDigit_2,
- chDigit_0, chDigit_6, chDigit_2, chDigit_3, chDigit_2, chDigit_7,
- chDigit_2, chDigit_0, chDigit_8, chDigit_8, chDigit_2, chDigit_8,
- chDigit_4, chDigit_3, chDigit_9, chDigit_6, chDigit_4, chDigit_3,
- chDigit_4, chDigit_1, chDigit_1,
- chLatin_E, chDash, chDigit_3, chDigit_2, chDigit_4, chNull
-};
-
-static const XMLCh DBL_MAX_NEGATIVE[] =
-{
- chDash,
- chDigit_8, chPeriod, chDigit_9, chDigit_8, chDigit_8, chDigit_4,
- chDigit_6, chDigit_5, chDigit_6, chDigit_7, chDigit_4, chDigit_3,
- chDigit_1, chDigit_1, chDigit_5, chDigit_7, chDigit_9, chDigit_5,
- chDigit_3, chDigit_8, chDigit_6, chDigit_4, chDigit_6, chDigit_5,
- chDigit_2, chDigit_5, chDigit_9, chDigit_5, chDigit_3, chDigit_9,
- chDigit_4, chDigit_5, chDigit_1,
- chLatin_E, chPlus, chDigit_3, chDigit_0, chDigit_7, chNull
-};
-
-static const XMLCh DBL_MIN_NEGATIVE[] =
-{
- chDash,
- chDigit_2, chPeriod, chDigit_4, chDigit_7, chDigit_0, chDigit_3,
- chDigit_2, chDigit_8, chDigit_2, chDigit_2, chDigit_9, chDigit_2,
- chDigit_0, chDigit_6, chDigit_2, chDigit_3, chDigit_2, chDigit_7,
- chDigit_2, chDigit_0, chDigit_8, chDigit_8, chDigit_2, chDigit_8,
- chDigit_4, chDigit_3, chDigit_9, chDigit_6, chDigit_4, chDigit_3,
- chDigit_4, chDigit_1, chDigit_1,
- chLatin_E, chDash, chDigit_3, chDigit_2, chDigit_4, chNull
-};
-
-//
-// maxNegativeValue < minNegativeValue < 0 < minPositiveValue < maxPositiveValue
-// They are all "Inclusive value"
-//
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <float.h>
-static XMLDouble* maxNegativeValue = 0;
-static XMLDouble* minNegativeValue = 0;
-static XMLDouble* minPositiveValue = 0;
-static XMLDouble* maxPositiveValue = 0;
-
-static XMLMutex* sDoubleMutex = 0;
-static XMLRegisterCleanup XMLDoubleCleanup;
+XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// ctor/dtor
@@ -237,94 +149,38 @@
{
}
-//
-//
void XMLDouble::checkBoundary(const XMLCh* const strValue)
{
- if (!sDoubleMutex)
- {
- XMLMutex* tmpMutex = new XMLMutex;
- if (XMLPlatformUtils::compareAndSwap((void**)&sDoubleMutex, tmpMutex, 0))
- {
- // Some other thread beat us to it, so let's clean up ours.
- delete tmpMutex;
- }
- else
- {
- //
- // the thread who creates the mutex succesfully, to
- // initialize the followings
- //
- maxNegativeValue = new XMLDouble(DBL_MAX_NEGATIVE);
- minNegativeValue = new XMLDouble(DBL_MIN_NEGATIVE);
- minPositiveValue = new XMLDouble(DBL_MIN_POSITIVE);
- maxPositiveValue = new XMLDouble(DBL_MAX_POSITIVE);
-
- // This is the real mutex. Register it for cleanup at Termination.
- XMLDoubleCleanup.registerCleanup(reinitXMLDouble);
- }
- }
-
- //
- // by-pass boundary check for boundary value itself
- //
- if (( XMLString::equals(strValue, DBL_MAX_NEGATIVE) ) ||
- ( XMLString::equals(strValue, DBL_MIN_NEGATIVE) ) ||
- ( XMLString::equals(strValue, DBL_MIN_POSITIVE) ) ||
- ( XMLString::equals(strValue, DBL_MAX_POSITIVE) ) )
- return;
+ char *nptr = XMLString::transcode(strValue);
+ ArrayJanitor<char> jan1(nptr);
+ int strLen = strlen(nptr);
+ char *endptr = 0;
+ errno = 0;
+ fValue = strtod(nptr, &endptr);
- // error: this < maxNegativeValue
- if ( compareValues(this, maxNegativeValue) == -1 )
+ // check if all chars are valid char
+ if ( (endptr - nptr) != strLen)
{
- ThrowXML2(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_maxNeg
- , strValue
- , DBL_MAX_NEGATIVE);
+ ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars);
}
- // error: this > maxPositiveValue
- if ( compareValues(this, maxPositiveValue) == 1 )
+ // check if overflow/underflow occurs
+ if (errno == ERANGE)
{
- ThrowXML2(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_maxPos
- , strValue
- , DBL_MAX_POSITIVE);
- }
+ if ( fValue < 0 )
+ {
+ fType = NegINF;
+ }
+ else if ( fValue > 0)
+ {
+ fType = PosINF;
+ }
+ else
+ {
+ fType = (getSign() == 1) ? PosZero : NegZero;
+ }
- // minNegativeValue < this < minPositiveValue
- // value is not be representable
- if (( compareValues(this, minNegativeValue) == 1 ) &&
- ( compareValues(this, minPositiveValue) == -1 ) )
- {
- ThrowXML3(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_minNegPos
- , strValue
- , DBL_MIN_NEGATIVE
- , DBL_MIN_POSITIVE);
}
-
-}
-
-// -----------------------------------------------------------------------
-// Notification that lazy data has been deleted
-// -----------------------------------------------------------------------
-void XMLDouble::reinitXMLDouble() {
-
- delete sDoubleMutex;
- sDoubleMutex = 0;
-
- delete maxNegativeValue;
- maxNegativeValue = 0;
-
- delete minNegativeValue;
- minNegativeValue = 0;
-
- delete minPositiveValue;
- minPositiveValue = 0;
-
- delete maxPositiveValue;
- maxPositiveValue = 0;
}
1.6 +10 -19 xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.hpp
Index: XMLAbstractDoubleFloat.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLAbstractDoubleFloat.hpp 4 Nov 2002 15:22:05 -0000 1.5
+++ XMLAbstractDoubleFloat.hpp 11 Dec 2002 00:20:02 -0000 1.6
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.6 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.5 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -90,9 +93,7 @@
#ifndef XML_ABSTRACT_DOUBLE_FLOAT_HPP
#define XML_ABSTRACT_DOUBLE_FLOAT_HPP
-#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLNumber.hpp>
-#include <xercesc/util/XMLBigDecimal.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -193,23 +194,13 @@
static int compareSpecial(const XMLAbstractDoubleFloat* const
specialValue
, const XMLAbstractDoubleFloat* const
normalValue);
- // -----------------------------------------------------------------------
- // Private data members
- //
- // fMantissa
- // the XMLBigDecimal holding the value of mantissa.
- //
- // fExponent
- // the XMLBigInteger holding the value of exponent.
- //
- // fType
- // the type of the object.
- //
- // -----------------------------------------------------------------------
-
- XMLBigDecimal* fMantissa;
- XMLBigInteger* fExponent;
+protected:
+ double fValue;
LiteralType fType;
+
+private:
+ int fSign;
+ XMLCh* fRawData;
};
inline bool XMLAbstractDoubleFloat::isSpecialValue() const
1.7 +32 -109 xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.cpp
Index: XMLAbstractDoubleFloat.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLAbstractDoubleFloat.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLAbstractDoubleFloat.cpp 4 Nov 2002 15:22:05 -0000 1.6
+++ XMLAbstractDoubleFloat.cpp 11 Dec 2002 00:20:02 -0000 1.7
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.7 2002/12/11 00:20:02 peiyongz
+ * Doing businesss in value space. Converting out-of-bound value into special
values.
+ *
* Revision 1.6 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
@@ -91,6 +94,7 @@
#include <xercesc/util/XMLAbstractDoubleFloat.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/NumberFormatException.hpp>
+#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/Janitor.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -105,19 +109,16 @@
// ctor/dtor
// ---------------------------------------------------------------------------
XMLAbstractDoubleFloat::XMLAbstractDoubleFloat()
-:fMantissa(0)
-,fExponent(0)
+:fValue(0)
,fType(Normal)
+,fSign(0)
+,fRawData(0)
{
}
XMLAbstractDoubleFloat::~XMLAbstractDoubleFloat()
{
- if (fMantissa)
- delete fMantissa;
-
- if (fExponent)
- delete fExponent;
+ delete [] fRawData;
}
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
@@ -125,6 +126,8 @@
if ((!strValue) || (!*strValue))
ThrowXML(NumberFormatException, XMLExcepts::XMLNUM_emptyString);
+ fRawData = XMLString::replicate(strValue); // preserve the raw data form
+
XMLCh* tmpStrValue = XMLString::replicate(strValue);
ArrayJanitor<XMLCh> janTmpName(tmpStrValue);
XMLString::trim(tmpStrValue);
@@ -134,133 +137,51 @@
if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) )
{
fType = NegINF;
+ fSign = -1;
return;
}
else if (XMLString::equals(tmpStrValue, XMLUni::fgNegZeroString) )
{
fType = NegZero;
+ fSign = -1;
return;
}
else if (XMLString::equals(tmpStrValue, XMLUni::fgPosZeroString) )
{
fType = PosZero;
+ fSign = 1;
return;
}
else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) )
{
fType = PosINF;
+ fSign = 1;
return;
}
else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) )
{
fType = NaN;
+ fSign = 1;
return;
}
//
// Normal case
//
- int ePos = 0;
- int tmpStrLen = XMLString::stringLen(tmpStrValue);
-
- if ((( ePos = XMLString::indexOf(tmpStrValue, chLatin_E)) != -1 ) ||
- (( ePos = XMLString::indexOf(tmpStrValue, chLatin_e)) != -1 ) )
- {
- XMLCh* tmpMantissa = new XMLCh [ePos+1];
- XMLString::subString(tmpMantissa, tmpStrValue, 0, ePos);
- ArrayJanitor<XMLCh> janMantissa(tmpMantissa);
- fMantissa = new XMLBigDecimal(tmpMantissa);
-
- //
- // 1234.56E78
- //
- if ( ePos < tmpStrLen - 1)
- {
- XMLCh* tmpExponent = new XMLCh [tmpStrLen - ePos];
- XMLString::subString(tmpExponent, tmpStrValue, ePos + 1, tmpStrLen);
- ArrayJanitor<XMLCh> janExponent(tmpExponent);
- fExponent = new XMLBigInteger(tmpExponent);
- }
- //
- // 1234.56E
- //
- else
- {
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_No_Exponent
- , strValue);
- }
-
- }
- else
- {
- fMantissa = new XMLBigDecimal(tmpStrValue);
- fExponent = new XMLBigInteger(XMLUni::fgZeroString);
- }
-
checkBoundary(tmpStrValue);
}
//
-// Add the 'E' as necessary
-// The caller needs to de-allocate the memory allocated by this function
-// Deallocate the memory allocated by XMLBigInteger
+//
//
XMLCh* XMLAbstractDoubleFloat::toString() const
{
- switch (fType)
- {
- case NegINF:
- return XMLString::replicate(XMLUni::fgNegINFString);
-
- case NegZero:
- return XMLString::replicate(XMLUni::fgNegZeroString);
-
- case PosZero:
- return XMLString::replicate(XMLUni::fgPosZeroString);
-
- case PosINF:
- return XMLString::replicate(XMLUni::fgPosINFString);
-
- case NaN:
- return XMLString::replicate(XMLUni::fgNaNString);
-
- case Normal:
-
- XMLCh *ret_mantissa;
- ret_mantissa = fMantissa->toString();
-
- if (fExponent)
- {
- XMLCh *ret_exponent = fExponent->toString();
- XMLCh *ret_val = new XMLCh [ XMLString::stringLen(ret_mantissa) +
- XMLString::stringLen(ret_exponent) + 2];
- *ret_val = 0;
- XMLString::catString(ret_val, ret_mantissa);
- XMLString::catString(ret_val, XMLUni::fgEString);
- XMLString::catString(ret_val, ret_exponent);
-
- delete [] ret_mantissa;
- delete [] ret_exponent;
- return ret_val;
- }
- else
- return ret_mantissa;
-
- break;
- default:
- XMLString::binToText(fType, value1, 16, 10);
- ThrowXML1(NumberFormatException
- , XMLExcepts::XMLNUM_DBL_FLT_InvalidType
- , value1);
- };
-
- return (XMLCh*) 0;
+ return XMLString::replicate(fRawData);
}
int XMLAbstractDoubleFloat::getSign() const
{
- return fMantissa->getSign();
+ return fSign;
}
//
@@ -276,16 +197,11 @@
if ((!lValue->isSpecialValue()) &&
(!rValue->isSpecialValue()) )
{
- //
- // if we use fValue to compare two
- // sequences "12.3456E4" and "1234.56E2",
- // they are _NOT_ the same. so we ask
- // BigDecimal to compare.
- //
- XMLBigDecimal ldv = XMLBigDecimal(*(lValue->fMantissa),
lValue->fExponent->intValue());
- XMLBigDecimal rdv = XMLBigDecimal(*(rValue->fMantissa),
rValue->fExponent->intValue());
+ if (lValue->fValue == rValue->fValue)
+ return 0;
+ else
+ return (lValue->fValue > rValue->fValue) ? 1: -1;
- return XMLBigDecimal::compareValues(&ldv, &rdv);
}
//
// case#2: lValue special
@@ -298,7 +214,7 @@
if (lValue->fType == rValue->fType)
return 0;
else
- return (lValue->fType > rValue->fType ? 1 : -1);
+ return (lValue->fType > rValue->fType) ? 1 : -1;
}
//
// case#3: lValue special
@@ -412,8 +328,15 @@
else
XMLString::copyString(inData, XMLUni::fgPosZeroString);
}
+ else
+ {
+ // we got to set the sign first, since this string may
+ // eventaully turn out to be beyond the minimum representable
+ // number and reduced to -0 or +0.
+ fSign = minusSeen ? -1 : 1;
+ }
- return;
+ return;
}
XERCES_CPP_NAMESPACE_END
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]