dbertoni 2004/07/29 13:45:19
Modified: c/src/xalanc/PlatformSupport DoubleSupport.cpp
DoubleSupport.hpp PlatformSupportInit.cpp
Log:
Cleaned up and simplified DoubleSupport.
Revision Changes Path
1.5 +481 -500 xml-xalan/c/src/xalanc/PlatformSupport/DoubleSupport.cpp
Index: DoubleSupport.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/PlatformSupport/DoubleSupport.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DoubleSupport.cpp 26 Feb 2004 22:34:18 -0000 1.4
+++ DoubleSupport.cpp 29 Jul 2004 20:45:19 -0000 1.5
@@ -17,10 +17,6 @@
-#if !defined(XALAN_NO_STD_NUMERIC_LIMITS)
-#include <limits>
-#endif
-
#include <clocale>
#include <cmath>
@@ -35,451 +31,436 @@
-#if defined(XALAN_NO_STD_NUMERIC_LIMITS)
-// To circumvent an OS/390 problem
-#if !defined(OS390)
-#define XALAN_POSITIVE_INFINITY HUGE_VAL
-#else
-
-static const union
-{
- unsigned char c[8];
- double d;
-} theHugeVal = { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } };
+DoubleSupport::NumberUnion DoubleSupport::s_NaN;
-#define XALAN_POSITIVE_INFINITY (theHugeVal.d)
+const DoubleSupport::NumberUnion DoubleSupport::s_positiveInfinity = {
HUGE_VAL };
-#endif
+const DoubleSupport::NumberUnion DoubleSupport::s_negativeInfinity = {
-HUGE_VAL };
-#if defined(_AIX)
-const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { DBL_QNAN };
-#else
-const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { sqrt(-2.01) };
-#endif
-const double DoubleSupport::s_positiveInfinity = XALAN_POSITIVE_INFINITY;
+const DoubleSupport::NumberUnion DoubleSupport::s_positiveZero = { 0.0 };
-#else
+const DoubleSupport::NumberUnion DoubleSupport::s_negativeZero = {
-s_positiveZero.d };
-#if defined(__SGI_STL_PORT)
-const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { sqrt(-2.01) };
-#else
-const DoubleSupport::NumberUnion DoubleSupport::s_NaN = {
std::numeric_limits<double>::quiet_NaN() };
-#endif
-const double DoubleSupport::s_positiveInfinity =
std::numeric_limits<double>::infinity();
+void
+DoubleSupport::initialize()
+{
+ // We initialize this at here because some
+ // platforms have had issues with signals
+ // if we call sqrt(-2.01) during static
+ // initialization.
+#if defined(XALAN_STRICT_ANSI_HEADERS)
+ s_NaN.d = std::sqrt(-2.01);
+#else
+ s_NaN.d = sqrt(-2.01);
#endif
+}
-const double DoubleSupport::s_negativeInfinity =
-DoubleSupport::s_positiveInfinity;
-
-const DoubleSupport::NumberUnion DoubleSupport::s_positiveZero = { 0.0 };
-#if !defined(_AIX)
-const DoubleSupport::NumberUnion DoubleSupport::s_negativeZero = {
-DoubleSupport::s_positiveZero.d };
-#else
-// Some compiler are overly aggressive and think that there is no such thing
as -0,
-// so we have to get it in a very sneaky way.
-double theDummy;
-
-const DoubleSupport::NumberUnion DoubleSupport::s_negativeZero = {
modf(-7.0, &theDummy) };
-#endif
+
+void
+DoubleSupport::terminate()
+{
+ s_NaN.d = 0.0L;
+}
bool
DoubleSupport::equal(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true || isNaN(theRHS) == true)
- {
- return false;
- }
- else
- {
- return theLHS == theRHS;
- }
+ if (isNaN(theLHS) == true || isNaN(theRHS) == true)
+ {
+ return false;
+ }
+ else
+ {
+ return theLHS == theRHS;
+ }
}
bool
DoubleSupport::lessThan(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true || isNaN(theRHS) == true)
- {
- return false;
- }
- else
- {
- return theLHS < theRHS;
- }
+ if (isNaN(theLHS) == true || isNaN(theRHS) == true)
+ {
+ return false;
+ }
+ else
+ {
+ return theLHS < theRHS;
+ }
}
bool
DoubleSupport::lessThanOrEqual(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true || isNaN(theRHS) == true)
- {
- return false;
- }
- else
- {
- return theLHS <= theRHS;
- }
+ if (isNaN(theLHS) == true || isNaN(theRHS) == true)
+ {
+ return false;
+ }
+ else
+ {
+ return theLHS <= theRHS;
+ }
}
bool
DoubleSupport::greaterThan(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true || isNaN(theRHS) == true)
- {
- return false;
- }
- else
- {
- return theLHS > theRHS;
- }
+ if (isNaN(theLHS) == true || isNaN(theRHS) == true)
+ {
+ return false;
+ }
+ else
+ {
+ return theLHS > theRHS;
+ }
}
bool
DoubleSupport::greaterThanOrEqual(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true || isNaN(theRHS) == true)
- {
- return false;
- }
- else
- {
- return theLHS >= theRHS;
- }
+ if (isNaN(theLHS) == true || isNaN(theRHS) == true)
+ {
+ return false;
+ }
+ else
+ {
+ return theLHS >= theRHS;
+ }
}
double
DoubleSupport::add(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true)
- {
- return theLHS;
- }
- else if (isNaN(theRHS) == true)
- {
- return theRHS;
- }
- else
- {
- return theLHS + theRHS;
- }
+ if (isNaN(theLHS) == true)
+ {
+ return theLHS;
+ }
+ else if (isNaN(theRHS) == true)
+ {
+ return theRHS;
+ }
+ else
+ {
+ return theLHS + theRHS;
+ }
}
double
DoubleSupport::subtract(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true)
- {
- return theLHS;
- }
- else if (isNaN(theRHS) == true)
- {
- return theRHS;
- }
- else
- {
- return theLHS - theRHS;
- }
+ if (isNaN(theLHS) == true)
+ {
+ return theLHS;
+ }
+ else if (isNaN(theRHS) == true)
+ {
+ return theRHS;
+ }
+ else
+ {
+ return theLHS - theRHS;
+ }
}
double
DoubleSupport::multiply(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true)
- {
- return theLHS;
- }
- else if (isNaN(theRHS) == true)
- {
- return theRHS;
- }
- else
- {
- return theLHS * theRHS;
- }
+ if (isNaN(theLHS) == true)
+ {
+ return theLHS;
+ }
+ else if (isNaN(theRHS) == true)
+ {
+ return theRHS;
+ }
+ else
+ {
+ return theLHS * theRHS;
+ }
}
double
DoubleSupport::divide(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true)
- {
- return theLHS;
- }
- else if (isNaN(theRHS) == true)
- {
- return theRHS;
- }
- else if (theRHS != 0.0L)
- {
- return theLHS / theRHS;
- }
- else if (theLHS == 0.0L)
- {
- // This is NaN...
- return DoubleSupport::getNaN();
- }
- else if (theLHS > 0.0L && isPositiveZero(theRHS) == true)
- {
- // This is positive infinity...
- return DoubleSupport::getPositiveInfinity();
- }
- else
- {
- // This is negative infinity...
- return DoubleSupport::getNegativeInfinity();
- }
+ if (isNaN(theLHS) == true)
+ {
+ return theLHS;
+ }
+ else if (isNaN(theRHS) == true)
+ {
+ return theRHS;
+ }
+ else if (theRHS != 0.0L)
+ {
+ return theLHS / theRHS;
+ }
+ else if (theLHS == 0.0L)
+ {
+ // This is NaN...
+ return DoubleSupport::getNaN();
+ }
+ else if (theLHS > 0.0L && isPositiveZero(theRHS) == true)
+ {
+ // This is positive infinity...
+ return DoubleSupport::getPositiveInfinity();
+ }
+ else
+ {
+ // This is negative infinity...
+ return DoubleSupport::getNegativeInfinity();
+ }
}
double
DoubleSupport::modulus(
- double theLHS,
- double theRHS)
+ double theLHS,
+ double theRHS)
{
- if (isNaN(theLHS) == true)
- {
- return theLHS;
- }
- else if (isNaN(theRHS) == true)
- {
- return theRHS;
- }
- else if (theRHS == 0.0)
- {
- return getNaN();
- }
- else if (long(theLHS) == theLHS && long(theRHS) == theRHS)
- {
- return long(theLHS) % long(theRHS);
- }
- else
- {
- double theDummy;
+ if (isNaN(theLHS) == true)
+ {
+ return theLHS;
+ }
+ else if (isNaN(theRHS) == true)
+ {
+ return theRHS;
+ }
+ else if (theRHS == 0.0)
+ {
+ return getNaN();
+ }
+ else if (long(theLHS) == theLHS && long(theRHS) == theRHS)
+ {
+ return long(theLHS) % long(theRHS);
+ }
+ else
+ {
+ double theDummy;
- double theResult = divide(theLHS, theRHS);
+ double theResult = divide(theLHS, theRHS);
#if defined(XALAN_STRICT_ANSI_HEADERS)
- return std::modf(theResult, &theDummy) * theRHS;
+ return std::modf(theResult, &theDummy) * theRHS;
#else
- return modf(theResult, &theDummy) * theRHS;
+ return modf(theResult, &theDummy) * theRHS;
#endif
- }
+ }
}
double
-DoubleSupport::negative(double theDouble)
+DoubleSupport::negative(double theDouble)
{
- if (isNaN(theDouble) == true)
- {
- return getNaN();
- }
- else
- {
- return -theDouble;
- }
+ if (isNaN(theDouble) == true)
+ {
+ return getNaN();
+ }
+ else
+ {
+ return -theDouble;
+ }
}
double
-DoubleSupport::toDouble(const XalanDOMString& theString)
+DoubleSupport::toDouble(const XalanDOMString& theString)
{
- return toDouble(c_wstr(theString));
+ return toDouble(c_wstr(theString));
}
inline void
-consumeWhitespace(const XalanDOMChar*& theString)
+consumeWhitespace(const XalanDOMChar*& theString)
{
- while(*theString != 0 &&
- isXMLWhitespace(*theString))
- {
- ++theString;
- }
+ while(*theString != 0 &&
+ isXMLWhitespace(*theString))
+ {
+ ++theString;
+ }
}
inline void
consumeWhitespace(
- const XalanDOMChar*& theString,
- XalanDOMString::size_type& theLength)
+ const XalanDOMChar*& theString,
+ XalanDOMString::size_type& theLength)
{
- while(*theString != 0 &&
- isXMLWhitespace(*theString))
- {
- ++theString;
- --theLength;
- }
+ while(*theString != 0 &&
+ isXMLWhitespace(*theString))
+ {
+ ++theString;
+ --theLength;
+ }
}
inline static void
-consumeNumbers(const XalanDOMChar*& theString)
+consumeNumbers(const XalanDOMChar*& theString)
{
- while(*theString &&
- *theString >= XalanUnicode::charDigit_0 &&
- *theString <= XalanUnicode::charDigit_9)
- {
- ++theString;
- }
+ while(*theString &&
+ *theString >= XalanUnicode::charDigit_0 &&
+ *theString <= XalanUnicode::charDigit_9)
+ {
+ ++theString;
+ }
}
static bool
doValidate(
- const XalanDOMChar* theString,
- bool&
fGotDecimalPoint)
+ const XalanDOMChar* theString,
+ bool& fGotDecimalPoint)
{
- assert(theString != 0);
+ assert(theString != 0);
- bool fError = false;
- bool fGotDigit = false;
- bool fGotMinus = false;
- bool fGotWhitespace = false;
-
- const XalanDOMChar* theCurrent = theString;
-
- // trim any whitespace
- consumeWhitespace(theCurrent);
-
- while(*theCurrent != 0 && fError == false)
- {
- switch(*theCurrent)
- {
- case XalanUnicode::charFullStop:
- if (fGotDecimalPoint == true || // can't have more than
one...
- fGotWhitespace == true) // can't have one after
whitespace...
- {
- fError = true;
- }
- else
- {
- fGotDecimalPoint = true;
-
- ++theCurrent;
- }
- break;
-
- case XalanUnicode::charHyphenMinus:
- if (fGotDecimalPoint == true ||
- fGotMinus == true ||
- fGotDigit == true ||
- fGotWhitespace == true)
- {
- // Error -- more than one, or in bad position.
- fError = true;
- }
- else
- {
- fGotMinus = true;
-
- ++theCurrent;
- }
- break;
-
- case XalanUnicode::charDigit_0:
- case XalanUnicode::charDigit_1:
- case XalanUnicode::charDigit_2:
- case XalanUnicode::charDigit_3:
- case XalanUnicode::charDigit_4:
- case XalanUnicode::charDigit_5:
- case XalanUnicode::charDigit_6:
- case XalanUnicode::charDigit_7:
- case XalanUnicode::charDigit_8:
- case XalanUnicode::charDigit_9:
- if (fGotWhitespace == true)
- {
- fError = true;
- }
- else
- {
- fGotDigit = true;
-
- consumeNumbers(theCurrent);
- }
- break;
-
- case XalanUnicode::charSpace:
- case XalanUnicode::charCR:
- case XalanUnicode::charHTab:
- case XalanUnicode::charLF:
- if (fGotWhitespace == true)
- {
- fError = true;
- }
- else
- {
- fGotWhitespace = true;
-
- consumeWhitespace(theCurrent);
- }
- break;
-
- default:
- fError = true;
- break;
- }
- }
-
- // If there was no error, check to see that we got
- // at least one digit. Otherwise, return false if
- // there was an error.
- return fError == false ? fGotDigit : false;
+ bool fError = false;
+ bool fGotDigit = false;
+ bool fGotMinus = false;
+ bool fGotWhitespace = false;
+
+ const XalanDOMChar* theCurrent = theString;
+
+ // trim any whitespace
+ consumeWhitespace(theCurrent);
+
+ while(*theCurrent != 0 && fError == false)
+ {
+ switch(*theCurrent)
+ {
+ case XalanUnicode::charFullStop:
+ if (fGotDecimalPoint == true || // can't have more than one...
+ fGotWhitespace == true) // can't have one after whitespace...
+ {
+ fError = true;
+ }
+ else
+ {
+ fGotDecimalPoint = true;
+
+ ++theCurrent;
+ }
+ break;
+
+ case XalanUnicode::charHyphenMinus:
+ if (fGotDecimalPoint == true ||
+ fGotMinus == true ||
+ fGotDigit == true ||
+ fGotWhitespace == true)
+ {
+ // Error -- more than one, or in bad position.
+ fError = true;
+ }
+ else
+ {
+ fGotMinus = true;
+
+ ++theCurrent;
+ }
+ break;
+
+ case XalanUnicode::charDigit_0:
+ case XalanUnicode::charDigit_1:
+ case XalanUnicode::charDigit_2:
+ case XalanUnicode::charDigit_3:
+ case XalanUnicode::charDigit_4:
+ case XalanUnicode::charDigit_5:
+ case XalanUnicode::charDigit_6:
+ case XalanUnicode::charDigit_7:
+ case XalanUnicode::charDigit_8:
+ case XalanUnicode::charDigit_9:
+ if (fGotWhitespace == true)
+ {
+ fError = true;
+ }
+ else
+ {
+ fGotDigit = true;
+
+ consumeNumbers(theCurrent);
+ }
+ break;
+
+ case XalanUnicode::charSpace:
+ case XalanUnicode::charCR:
+ case XalanUnicode::charHTab:
+ case XalanUnicode::charLF:
+ if (fGotWhitespace == true)
+ {
+ fError = true;
+ }
+ else
+ {
+ fGotWhitespace = true;
+
+ consumeWhitespace(theCurrent);
+ }
+ break;
+
+ default:
+ fError = true;
+ break;
+ }
+ }
+
+ // If there was no error, check to see that we got
+ // at least one digit. Otherwise, return false if
+ // there was an error.
+ return fError == false ? fGotDigit : false;
}
static bool
-doValidate(const XalanDOMChar* theString)
+doValidate(const XalanDOMChar* theString)
{
- bool fDummy = false;
+ bool fDummy = false;
- return doValidate(theString, fDummy);
+ return doValidate(theString, fDummy);
}
@@ -487,70 +468,70 @@
#if defined(XALAN_NON_ASCII_PLATFORM)
void
translateWideString(
- const XalanDOMChar* theWideString,
- char*
theNarrowString,
- XalanDOMString::size_type theStringLength,
- char
theDecimalPointCharacter)
-{
- for(XalanDOMString::size_type i = 0; i < theStringLength; ++i)
- {
- switch(theWideString[i])
- {
- case XalanUnicode::charHyphenMinus:
- theNarrowString[i] = '-';
- break;
-
- case XalanUnicode::charFullStop:
- theNarrowString[i] = theDecimalPointCharacter;
- break;
-
- case XalanUnicode::charDigit_0:
- theNarrowString[i] = '0';
- break;
-
- case XalanUnicode::charDigit_1:
- theNarrowString[i] = '1';
- break;
-
- case XalanUnicode::charDigit_2:
- theNarrowString[i] = '2';
- break;
-
- case XalanUnicode::charDigit_3:
- theNarrowString[i] = '3';
- break;
-
- case XalanUnicode::charDigit_4:
- theNarrowString[i] = '4';
- break;
-
- case XalanUnicode::charDigit_5:
- theNarrowString[i] = '5';
- break;
-
- case XalanUnicode::charDigit_6:
- theNarrowString[i] = '6';
- break;
-
- case XalanUnicode::charDigit_7:
- theNarrowString[i] = '7';
- break;
-
- case XalanUnicode::charDigit_8:
- theNarrowString[i] = '8';
- break;
-
- case XalanUnicode::charDigit_9:
- theNarrowString[i] = '9';
- break;
-
- default:
- theNarrowString[i] = char(0);
- break;
- }
- }
-
- theNarrowString[theStringLength] = char(0);
+ const XalanDOMChar* theWideString,
+ char* theNarrowString,
+ XalanDOMString::size_type theStringLength,
+ char theDecimalPointCharacter)
+{
+ for(XalanDOMString::size_type i = 0; i < theStringLength; ++i)
+ {
+ switch(theWideString[i])
+ {
+ case XalanUnicode::charHyphenMinus:
+ theNarrowString[i] = '-';
+ break;
+
+ case XalanUnicode::charFullStop:
+ theNarrowString[i] = theDecimalPointCharacter;
+ break;
+
+ case XalanUnicode::charDigit_0:
+ theNarrowString[i] = '0';
+ break;
+
+ case XalanUnicode::charDigit_1:
+ theNarrowString[i] = '1';
+ break;
+
+ case XalanUnicode::charDigit_2:
+ theNarrowString[i] = '2';
+ break;
+
+ case XalanUnicode::charDigit_3:
+ theNarrowString[i] = '3';
+ break;
+
+ case XalanUnicode::charDigit_4:
+ theNarrowString[i] = '4';
+ break;
+
+ case XalanUnicode::charDigit_5:
+ theNarrowString[i] = '5';
+ break;
+
+ case XalanUnicode::charDigit_6:
+ theNarrowString[i] = '6';
+ break;
+
+ case XalanUnicode::charDigit_7:
+ theNarrowString[i] = '7';
+ break;
+
+ case XalanUnicode::charDigit_8:
+ theNarrowString[i] = '8';
+ break;
+
+ case XalanUnicode::charDigit_9:
+ theNarrowString[i] = '9';
+ break;
+
+ default:
+ theNarrowString[i] = char(0);
+ break;
+ }
+ }
+
+ theNarrowString[theStringLength] = char(0);
}
#endif
@@ -558,186 +539,186 @@
inline double
convertHelper(
- const XalanDOMChar* theString,
- bool
fGotDecimalPoint)
+ const XalanDOMChar* theString,
+ bool fGotDecimalPoint)
{
- // This is a big hack. If the length of the
- // string is less than n characters, we'll convert
- // it as a long and coerce that to a double. This
- // is _much_ cheaper...
- const XalanDOMString::size_type theLongHackThreshold = 10;
-
- XalanDOMString::size_type theLength = length(theString);
-
- if (fGotDecimalPoint == false && theLength < theLongHackThreshold)
- {
- return double(WideStringToLong(theString));
- }
- else
- {
+ // This is a big hack. If the length of the
+ // string is less than n characters, we'll convert
+ // it as a long and coerce that to a double. This
+ // is _much_ cheaper...
+ const XalanDOMString::size_type theLongHackThreshold = 10;
+
+ XalanDOMString::size_type theLength = length(theString);
+
+ if (fGotDecimalPoint == false && theLength < theLongHackThreshold)
+ {
+ return double(WideStringToLong(theString));
+ }
+ else
+ {
#if defined(XALAN_STRICT_ANSI_HEADERS)
- const char theDecimalPointChar =
std::localeconv()->decimal_point[0];
+ const char theDecimalPointChar =
std::localeconv()->decimal_point[0];
#else
- const char theDecimalPointChar =
localeconv()->decimal_point[0];
+ const char theDecimalPointChar = localeconv()->decimal_point[0];
#endif
- // trim any whitespace
- consumeWhitespace(theString, theLength);
+ // trim any whitespace
+ consumeWhitespace(theString, theLength);
- // Use a stack-based buffer, when possible...
- const XalanDOMString::size_type theBufferSize = 200u;
+ // Use a stack-based buffer, when possible...
+ const XalanDOMString::size_type theBufferSize = 200u;
- if (theLength < theBufferSize)
- {
- char theBuffer[theBufferSize];
+ if (theLength < theBufferSize)
+ {
+ char theBuffer[theBufferSize];
#if defined(XALAN_NON_ASCII_PLATFORM)
- translateWideString(theString, theBuffer, theLength,
theDecimalPointChar);
+ translateWideString(theString, theBuffer, theLength,
theDecimalPointChar);
#else
- for(XalanDOMString::size_type i = 0; i < theLength; ++i)
- {
- if (theString[i] == XalanUnicode::charFullStop)
- {
- theBuffer[i] = theDecimalPointChar;
- }
- else
- {
- theBuffer[i] = char(theString[i]);
- }
- }
+ for(XalanDOMString::size_type i = 0; i < theLength; ++i)
+ {
+ if (theString[i] == XalanUnicode::charFullStop)
+ {
+ theBuffer[i] = theDecimalPointChar;
+ }
+ else
+ {
+ theBuffer[i] = char(theString[i]);
+ }
+ }
- theBuffer[theLength] = '\0';
+ theBuffer[theLength] = '\0';
#endif
#if defined(XALAN_STRICT_ANSI_HEADERS)
- return std::atof(theBuffer);
+ return std::atof(theBuffer);
#else
- return atof(theBuffer);
+ return atof(theBuffer);
#endif
- }
- else
- {
- CharVectorType theVector;
+ }
+ else
+ {
+ CharVectorType theVector;
#if !defined(XALAN_NON_ASCII_PLATFORM)
- theVector.reserve(theLength + 1);
+ theVector.reserve(theLength + 1);
- CopyWideStringToVector(theString, theVector);
+ CopyWideStringToVector(theString, theVector);
#else
- theVector.resize(theLength + 1,
CharVectorType::value_type(0));
+ theVector.resize(theLength + 1, CharVectorType::value_type(0));
- translateWideString(theString, &*theVector.begin(),
theLength, theDecimalPointChar);
+ translateWideString(theString, &*theVector.begin(), theLength,
theDecimalPointChar);
#endif
#if defined(XALAN_STRICT_ANSI_HEADERS)
- return std::atof(&*theVector.begin());
+ return std::atof(&*theVector.begin());
#else
- return atof(&*theVector.begin());
+ return atof(&*theVector.begin());
#endif
- }
- }
+ }
+ }
}
double
-doConvert(const XalanDOMChar* theString)
+doConvert(const XalanDOMChar* theString)
{
- assert(theString != 0);
- assert(*theString != 0);
+ assert(theString != 0);
+ assert(*theString != 0);
- bool fGotDecimalPoint = false;
+ bool fGotDecimalPoint = false;
- if (doValidate(theString, fGotDecimalPoint) == false)
- {
- return DoubleSupport::getNaN();
- }
- else
- {
- return convertHelper(theString, fGotDecimalPoint);
- }
+ if (doValidate(theString, fGotDecimalPoint) == false)
+ {
+ return DoubleSupport::getNaN();
+ }
+ else
+ {
+ return convertHelper(theString, fGotDecimalPoint);
+ }
}
double
-DoubleSupport::toDouble(const XalanDOMChar* theString)
+DoubleSupport::toDouble(const XalanDOMChar* theString)
{
- if (theString == 0 ||
- *theString == 0)
- {
- return getNaN();
- }
- else
- {
- return doConvert(theString);
- }
+ if (theString == 0 ||
+ *theString == 0)
+ {
+ return getNaN();
+ }
+ else
+ {
+ return doConvert(theString);
+ }
}
bool
-DoubleSupport::isValid(const XalanDOMString& theString)
+DoubleSupport::isValid(const XalanDOMString& theString)
{
- return isValid(c_wstr(theString));
+ return isValid(c_wstr(theString));
}
bool
-DoubleSupport::isValid(const XalanDOMChar* theString)
+DoubleSupport::isValid(const XalanDOMChar* theString)
{
- return doValidate(theString);
+ return doValidate(theString);
}
double
-DoubleSupport::round(double theValue)
+DoubleSupport::round(double theValue)
{
- if (isNaN(theValue))
- {
- return getNaN();
- }
- else if (isPositiveInfinity(theValue))
- {
- return getPositiveInfinity();
- }
- if (isNegativeInfinity(theValue))
- {
- return getNegativeInfinity();
- }
- else if (theValue == 0)
- {
- return 0.0;
- }
- else if (theValue > 0)
- {
- return long(theValue + 0.5);
- }
- else
- {
- // Negative numbers are a special case. Any time we
- // have -0.5 as the fractional part, we have to
- // round up (toward 0), rather than down.
- double intPart = 0;
+ if (isNaN(theValue))
+ {
+ return getNaN();
+ }
+ else if (isPositiveInfinity(theValue))
+ {
+ return getPositiveInfinity();
+ }
+ if (isNegativeInfinity(theValue))
+ {
+ return getNegativeInfinity();
+ }
+ else if (theValue == 0)
+ {
+ return 0.0;
+ }
+ else if (theValue > 0)
+ {
+ return long(theValue + 0.5);
+ }
+ else
+ {
+ // Negative numbers are a special case. Any time we
+ // have -0.5 as the fractional part, we have to
+ // round up (toward 0), rather than down.
+ double intPart = 0;
#if defined(XALAN_STRICT_ANSI_HEADERS)
- const double fracPart = std::modf(theValue, &intPart);
+ const double fracPart = std::modf(theValue, &intPart);
#else
- const double fracPart = modf(theValue, &intPart);
+ const double fracPart = modf(theValue, &intPart);
#endif
- if (fracPart == -0.5)
- {
- // special case -- we have have to round toward 0...
- return long(theValue + 0.5);
- }
- else
- {
- return long(theValue - 0.5);
- }
- }
+ if (fracPart == -0.5)
+ {
+ // special case -- we have have to round toward 0...
+ return long(theValue + 0.5);
+ }
+ else
+ {
+ return long(theValue - 0.5);
+ }
+ }
}
1.5 +556 -543 xml-xalan/c/src/xalanc/PlatformSupport/DoubleSupport.hpp
Index: DoubleSupport.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/PlatformSupport/DoubleSupport.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DoubleSupport.hpp 26 Feb 2004 22:34:18 -0000 1.4
+++ DoubleSupport.hpp 29 Jul 2004 20:45:19 -0000 1.5
@@ -41,559 +41,572 @@
{
public:
- // Use these functions to determine if a value represents one of these
- // values. It seems that under some architectures, NaN will compare
- // as equal to any number, which is a big problem. Hence these helper
- // functions.
-
- /**
- * Determine if target is not a number
- *
- * @param theNumber target number
- * @return true if target represents the "not a number" value
- */
- static bool
- isNaN(double theNumber)
- {
- const NumberUnion temp = { theNumber };
-
- return s_NaN.dwords.dw1 == temp.dwords.dw1 &&
- s_NaN.dwords.dw2 == temp.dwords.dw2;
- }
-
- /**
- * Determine if target is positive infinity
- *
- * @param theNumber target number
- * @return true if target represents the value for positive infinity
- */
- static bool
- isPositiveInfinity(double theNumber)
- {
- return !isNaN(theNumber) && theNumber == s_positiveInfinity;
- }
-
- /**
- * Determine if target is negative infinity
- *
- * @param theNumber target number
- * @return true if target represents the value for negative infinity
- */
- static bool
- isNegativeInfinity(double theNumber)
- {
- return !isNaN(theNumber) && theNumber == s_negativeInfinity;
- }
-
- /**
- * Determine if target is positive 0.
- *
- * @param theNumber target number
- * @return true if target represents the value for positive 0.
- */
- static bool
- isPositiveZero(double theNumber)
- {
- const NumberUnion temp = { theNumber };
-
- return s_positiveZero.dwords.dw1 == temp.dwords.dw1 &&
- s_positiveZero.dwords.dw2 == temp.dwords.dw2;
- }
-
- /**
- * Determine if target is negative 0
- *
- * @param theNumber target number
- * @return true if target represents the value for negative 0
- */
- static bool
- isNegativeZero(double theNumber)
- {
- const NumberUnion temp = { theNumber };
-
- return s_negativeZero.dwords.dw1 == temp.dwords.dw1 &&
- s_negativeZero.dwords.dw2 == temp.dwords.dw2;
- }
-
- // These can be used to initialize values, but should not
- // be used to do equality comparisons, as == may fail on
- // some platforms.
- //
-
- /**
- * Double value that represents "not a number"
- *
- * @return "not a number" value
- */
- static double
- getNaN()
- {
- return s_NaN.d;
- }
-
- /**
- * Double value that represents positive infinity
- *
- * @return positive infinity value
- */
- static double
- getPositiveInfinity()
- {
- return s_positiveInfinity;
- }
-
- /**
- * Double value that represents negative infinity
- *
- * @return negative infinity value
- */
- static double
- getNegativeInfinity()
- {
- return s_negativeInfinity;
- }
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- equal(
- double theLHS,
- double theRHS);
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- notEqual(
- double theLHS,
- double theRHS)
- {
- return !equal(theLHS, theRHS);
- }
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- lessThan(
- double theLHS,
- double theRHS);
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- lessThanOrEqual(
- double theLHS,
- double theRHS);
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- greaterThan(
- double theLHS,
- double theRHS);
-
- /**
- * Compare two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to compare
- * @param theRHS a number to compare
- * @return the result of the compare
- */
- static bool
- greaterThanOrEqual(
- double theLHS,
- double theRHS);
-
- /**
- * Add two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to add
- * @param theRHS a number to add
- * @return the result of the addition
- */
- static double
- add(
- double theLHS,
- double theRHS);
-
- /**
- * Subtract two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to subtract
- * @param theRHS a number to subtract
- * @return the result of the subtraction
- */
- static double
- subtract(
- double theLHS,
- double theRHS);
-
- /**
- * Multiply two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to multiply
- * @param theRHS a number to multiply
- * @return the result of the multiplication
- */
- static double
- multiply(
- double theLHS,
- double theRHS);
-
- /**
- * Divide two double values, taking into account
- * the fact that we must support IEEE 754
- *
- * @param theLHS a number to divide
- * @param theRHS a number to divide
- * @return the result of the division
- */
- static double
- divide(
- double theLHS,
- double theRHS);
-
- /**
- * Determine the modulus two double values,
- * taking into account the fact that we must
- * support IEEE 754
- *
- * @param theLHS a number to divide
- * @param theRHS a number to divide
- * @return the result of the modulus
- */
- static double
- modulus(
- double theLHS,
- double theRHS);
-
- /**
- * Determine the negative of a double value,
- * taking into account the fact that we must
- * support IEEE 754
- *
- * @param theDouble a number to negate
- * @return the result of the negation
- */
- static double
- negative(double theDouble);
-
- // Some functors to do the same thing. This is for
- // STL integration...
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct equalFunction : public binary_function<const double&, const
double&, bool>
- #else
- struct equalFunction : public std::binary_function<const double&, const
double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return equal(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct notEqualFunction : public binary_function<const double&, const
double&, bool>
- #else
- struct notEqualFunction : public std::binary_function<const double&,
const double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return notEqual(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct lessThanFunction : public binary_function<const double&, const
double&, bool>
- #else
- struct lessThanFunction : public std::binary_function<const double&,
const double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return lessThan(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct lessThanOrEqualFunction : public binary_function<const double&,
const double&, bool>
- #else
- struct lessThanOrEqualFunction : public std::binary_function<const
double&, const double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return lessThanOrEqual(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct greaterThanFunction : public binary_function<const double&,
const double&, bool>
- #else
- struct greaterThanFunction : public std::binary_function<const double&,
const double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return greaterThan(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct greaterThanOrEqualFunction : public binary_function<const
double&, const double&, bool>
- #else
- struct greaterThanOrEqualFunction : public std::binary_function<const
double&, const double&, bool>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return greaterThanOrEqual(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct addFunction : public binary_function<const double&, const
double&, double>
- #else
- struct addFunction : public std::binary_function<const double&, const
double&, double>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return add(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct subtractFunction : public binary_function<const double&, const
double&, double>
- #else
- struct subtractFunction : public std::binary_function<const double&,
const double&, double>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return subtract(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct multiplyFunction : public binary_function<const double&, const
double&, double>
- #else
- struct multiplyFunction : public std::binary_function<const double&,
const double&, double>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return multiply(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct divideFunction : public binary_function<const double&, const
double&, double>
- #else
- struct divideFunction : public std::binary_function<const double&,
const double&, double>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return divide(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct modulusFunction : public binary_function<const double&, const
double&, double>
- #else
- struct modulusFunction : public std::binary_function<const double&,
const double&, double>
- #endif
- {
- result_type
- operator()(
- first_argument_type theLHS,
- second_argument_type theRHS) const
- {
- return modulus(theLHS, theRHS);
- }
- };
-
- #if defined(XALAN_NO_STD_NAMESPACE)
- struct negativeFunction : public unary_function<const double&, double>
- #else
- struct negativeFunction : public std::unary_function<const double&,
double>
- #endif
- {
- result_type
- operator()(argument_type theDouble) const
- {
- return negative(theDouble);
- }
- };
-
- /**
- * Determine whether or not a string contains
- * a valid floating point number.
- *
- * @param theString The string to check.
- * @return true if the string is valid, false if not.
- */
- static bool
- isValid(const XalanDOMString& theString);
-
- /**
- * Determine whether or not a string contains
- * a valid floating point number.
- *
- * @param theString The string to check.
- * @return true if the string is valid, false if not.
- */
- static bool
- isValid(const XalanDOMChar* theString);
-
- /**
- * Convert a string to a double value. Returns
- * NaN if the string is not a valid floating
- * point number.
- *
- * @param theString The string to convert.
- * @return The result of the conversion
- */
- static double
- toDouble(const XalanDOMString& theString);
-
- /**
- * Convert a string to a double value. Returns
- * NaN if the string is not a valid floating
- * point number.
- *
- * @param theString The string to convert.
- * @return The result of the conversion
- */
- static double
- toDouble(const XalanDOMChar* theString);
-
- /**
- * Round a number according to the XPath
- * rules.
- *
- * @param theValue The value to round.
- * @return The result of the rounding
- */
- static double
- round(double theValue);
-
- /**
- * Returns the ceiling of a number according to the XPath
- * rules.
- *
- * @param theValue The value to round.
- * @return The result of the rounding
- */
- static double
- ceiling(double theValue)
- {
+ /**
+ * Perform static initialization. See class PlatformSupportInit.
+ */
+ static void
+ initialize();
+
+ /**
+ * Perform static shut down. See class PlatformSupportInit.
+ */
+ static void
+ terminate();
+
+
+ // Use these functions to determine if a value represents one of these
+ // specia values. On some platforms, regular C/C++ operators don't work
+ // as we need them too, so we have these helper functions.
+
+ /**
+ * Determine if target is not a number
+ *
+ * @param theNumber target number
+ * @return true if target represents the "not a number" value
+ */
+ static bool
+ isNaN(double theNumber)
+ {
+ return s_NaN == theNumber;
+ }
+
+ /**
+ * Determine if target is positive infinity
+ *
+ * @param theNumber target number
+ * @return true if target represents the value for positive infinity
+ */
+ static bool
+ isPositiveInfinity(double theNumber)
+ {
+ return s_positiveInfinity == theNumber;
+ }
+
+ /**
+ * Determine if target is negative infinity
+ *
+ * @param theNumber target number
+ * @return true if target represents the value for negative infinity
+ */
+ static bool
+ isNegativeInfinity(double theNumber)
+ {
+ return s_negativeInfinity == theNumber;
+ }
+
+ /**
+ * Determine if target is positive 0.
+ *
+ * @param theNumber target number
+ * @return true if target represents the value for positive 0.
+ */
+ static bool
+ isPositiveZero(double theNumber)
+ {
+ return s_positiveZero == theNumber;
+ }
+
+ /**
+ * Determine if target is negative 0
+ *
+ * @param theNumber target number
+ * @return true if target represents the value for negative 0
+ */
+ static bool
+ isNegativeZero(double theNumber)
+ {
+ return s_negativeZero == theNumber;
+ }
+
+ // These can be used to initialize values, but should not
+ // be used to do equality comparisons, as == may fail on
+ // some platforms.
+ //
+
+ /**
+ * Double value that represents "not a number"
+ *
+ * @return "not a number" value
+ */
+ static double
+ getNaN()
+ {
+ return s_NaN.d;
+ }
+
+ /**
+ * Double value that represents positive infinity
+ *
+ * @return positive infinity value
+ */
+ static double
+ getPositiveInfinity()
+ {
+ return s_positiveInfinity.d;
+ }
+
+ /**
+ * Double value that represents negative infinity
+ *
+ * @return negative infinity value
+ */
+ static double
+ getNegativeInfinity()
+ {
+ return s_negativeInfinity.d;
+ }
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ equal(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ notEqual(
+ double theLHS,
+ double theRHS)
+ {
+ return !equal(theLHS, theRHS);
+ }
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ lessThan(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ lessThanOrEqual(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ greaterThan(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Compare two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to compare
+ * @param theRHS a number to compare
+ * @return the result of the compare
+ */
+ static bool
+ greaterThanOrEqual(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Add two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to add
+ * @param theRHS a number to add
+ * @return the result of the addition
+ */
+ static double
+ add(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Subtract two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to subtract
+ * @param theRHS a number to subtract
+ * @return the result of the subtraction
+ */
+ static double
+ subtract(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Multiply two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to multiply
+ * @param theRHS a number to multiply
+ * @return the result of the multiplication
+ */
+ static double
+ multiply(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Divide two double values, taking into account
+ * the fact that we must support IEEE 754
+ *
+ * @param theLHS a number to divide
+ * @param theRHS a number to divide
+ * @return the result of the division
+ */
+ static double
+ divide(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Determine the modulus two double values,
+ * taking into account the fact that we must
+ * support IEEE 754
+ *
+ * @param theLHS a number to divide
+ * @param theRHS a number to divide
+ * @return the result of the modulus
+ */
+ static double
+ modulus(
+ double theLHS,
+ double theRHS);
+
+ /**
+ * Determine the negative of a double value,
+ * taking into account the fact that we must
+ * support IEEE 754
+ *
+ * @param theDouble a number to negate
+ * @return the result of the negation
+ */
+ static double
+ negative(double theDouble);
+
+ // Some functors to do the same thing. This is for
+ // STL integration...
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct equalFunction : public binary_function<const double&, const
double&, bool>
+ #else
+ struct equalFunction : public std::binary_function<const double&, const
double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return equal(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct notEqualFunction : public binary_function<const double&, const
double&, bool>
+ #else
+ struct notEqualFunction : public std::binary_function<const double&,
const double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return notEqual(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct lessThanFunction : public binary_function<const double&, const
double&, bool>
+ #else
+ struct lessThanFunction : public std::binary_function<const double&,
const double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return lessThan(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct lessThanOrEqualFunction : public binary_function<const double&,
const double&, bool>
+ #else
+ struct lessThanOrEqualFunction : public std::binary_function<const
double&, const double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return lessThanOrEqual(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct greaterThanFunction : public binary_function<const double&, const
double&, bool>
+ #else
+ struct greaterThanFunction : public std::binary_function<const double&,
const double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return greaterThan(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct greaterThanOrEqualFunction : public binary_function<const
double&, const double&, bool>
+ #else
+ struct greaterThanOrEqualFunction : public std::binary_function<const
double&, const double&, bool>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return greaterThanOrEqual(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct addFunction : public binary_function<const double&, const
double&, double>
+ #else
+ struct addFunction : public std::binary_function<const double&, const
double&, double>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return add(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct subtractFunction : public binary_function<const double&, const
double&, double>
+ #else
+ struct subtractFunction : public std::binary_function<const double&,
const double&, double>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return subtract(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct multiplyFunction : public binary_function<const double&, const
double&, double>
+ #else
+ struct multiplyFunction : public std::binary_function<const double&,
const double&, double>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return multiply(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct divideFunction : public binary_function<const double&, const
double&, double>
+ #else
+ struct divideFunction : public std::binary_function<const double&, const
double&, double>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return divide(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct modulusFunction : public binary_function<const double&, const
double&, double>
+ #else
+ struct modulusFunction : public std::binary_function<const double&,
const double&, double>
+ #endif
+ {
+ result_type
+ operator()(
+ first_argument_type theLHS,
+ second_argument_type theRHS) const
+ {
+ return modulus(theLHS, theRHS);
+ }
+ };
+
+ #if defined(XALAN_NO_STD_NAMESPACE)
+ struct negativeFunction : public unary_function<const double&, double>
+ #else
+ struct negativeFunction : public std::unary_function<const double&,
double>
+ #endif
+ {
+ result_type
+ operator()(argument_type theDouble) const
+ {
+ return negative(theDouble);
+ }
+ };
+
+ /**
+ * Determine whether or not a string contains
+ * a valid floating point number.
+ *
+ * @param theString The string to check.
+ * @return true if the string is valid, false if not.
+ */
+ static bool
+ isValid(const XalanDOMString& theString);
+
+ /**
+ * Determine whether or not a string contains
+ * a valid floating point number.
+ *
+ * @param theString The string to check.
+ * @return true if the string is valid, false if not.
+ */
+ static bool
+ isValid(const XalanDOMChar* theString);
+
+ /**
+ * Convert a string to a double value. Returns
+ * NaN if the string is not a valid floating
+ * point number.
+ *
+ * @param theString The string to convert.
+ * @return The result of the conversion
+ */
+ static double
+ toDouble(const XalanDOMString& theString);
+
+ /**
+ * Convert a string to a double value. Returns
+ * NaN if the string is not a valid floating
+ * point number.
+ *
+ * @param theString The string to convert.
+ * @return The result of the conversion
+ */
+ static double
+ toDouble(const XalanDOMChar* theString);
+
+ /**
+ * Round a number according to the XPath
+ * rules.
+ *
+ * @param theValue The value to round.
+ * @return The result of the rounding
+ */
+ static double
+ round(double theValue);
+
+ /**
+ * Returns the ceiling of a number according to the XPath
+ * rules.
+ *
+ * @param theValue The value to round.
+ * @return The result of the rounding
+ */
+ static double
+ ceiling(double theValue)
+ {
#if defined(XALAN_STRICT_ANSI_HEADERS)
- return std::ceil(theValue);
+ return std::ceil(theValue);
#else
- return ceil(theValue);
+ return ceil(theValue);
#endif
- }
+ }
- /**
- * Returns the floor of a number according to the XPath
- * rules.
- *
- * @param theValue The value to round.
- * @return The result of the rounding
- */
- static double
- floor(double theValue)
- {
+ /**
+ * Returns the floor of a number according to the XPath
+ * rules.
+ *
+ * @param theValue The value to round.
+ * @return The result of the rounding
+ */
+ static double
+ floor(double theValue)
+ {
#if defined(XALAN_STRICT_ANSI_HEADERS)
- return std::floor(theValue);
+ return std::floor(theValue);
#else
- return ::floor(theValue);
+ return ::floor(theValue);
#endif
- }
+ }
- typedef union
- {
- double d;
- struct
- {
- unsigned int dw1;
- unsigned int dw2;
- } dwords;
- } NumberUnion;
+ typedef union
+ {
+ double d;
+ struct
+ {
+ unsigned int dw1;
+ unsigned int dw2;
+ } dwords;
+
+ bool
+ operator==(double theNumber) const
+ {
+ const NumberUnion temp = { theNumber };
+
+ return dwords.dw1 == temp.dwords.dw1 &&
+ dwords.dw2 == temp.dwords.dw2;
+ }
+
+ } NumberUnion;
private:
- static const NumberUnion s_NaN;
- static const double s_positiveInfinity;
- static const double s_negativeInfinity;
- static const NumberUnion s_positiveZero;
- static const NumberUnion s_negativeZero;
+ static NumberUnion s_NaN;
+ static const NumberUnion s_positiveInfinity;
+ static const NumberUnion s_negativeInfinity;
+ static const NumberUnion s_positiveZero;
+ static const NumberUnion s_negativeZero;
};
@@ -602,4 +615,4 @@
-#endif // DOUBLESUPPORT_HEADER_GUARD_1357924680
+#endif // DOUBLESUPPORT_HEADER_GUARD_1357924680
1.6 +5 -0
xml-xalan/c/src/xalanc/PlatformSupport/PlatformSupportInit.cpp
Index: PlatformSupportInit.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/xalanc/PlatformSupport/PlatformSupportInit.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PlatformSupportInit.cpp 26 Feb 2004 22:34:18 -0000 1.5
+++ PlatformSupportInit.cpp 29 Jul 2004 20:45:19 -0000 1.6
@@ -18,6 +18,7 @@
+#include "DoubleSupport.hpp"
#include "XalanMessageLoader.hpp"
#include "XalanTranscodingServices.hpp"
@@ -59,6 +60,8 @@
void
PlatformSupportInit::initialize()
{
+ DoubleSupport::initialize();
+
XalanMessageLoader::createLoader();
XalanTranscodingServices::initialize();
@@ -72,6 +75,8 @@
XalanTranscodingServices::terminate();
XalanMessageLoader::destroyLoader();
+
+ DoubleSupport::terminate();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]