dbertoni 2003/01/06 16:42:48
Modified: c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp
Log:
New implementation of special floating-point values.
Revision Changes Path
1.38 +9 -53 xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp
Index: DoubleSupport.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- DoubleSupport.cpp 20 Nov 2002 02:27:13 -0000 1.37
+++ DoubleSupport.cpp 7 Jan 2003 00:42:48 -0000 1.38
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -93,18 +93,18 @@
#endif
#if defined(_AIX)
-const double DoubleSupport::s_NaN = DBL_QNAN;
+const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { DBL_QNAN };
#else
-const double DoubleSupport::s_NaN = sqrt(-2.01);
+const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { sqrt(-2.01) };
#endif
const double DoubleSupport::s_positiveInfinity = XALAN_POSITIVE_INFINITY;
#else
#if defined(__SGI_STL_PORT)
-const double DoubleSupport::s_NaN = sqrt(-2.01);
+const DoubleSupport::NumberUnion DoubleSupport::s_NaN = { sqrt(-2.01) };
#else
-const double DoubleSupport::s_NaN = std::numeric_limits<double>::quiet_NaN();
+const DoubleSupport::NumberUnion DoubleSupport::s_NaN = {
std::numeric_limits<double>::quiet_NaN() };
#endif
const double DoubleSupport::s_positiveInfinity =
std::numeric_limits<double>::infinity();
@@ -112,53 +112,19 @@
#endif
const double DoubleSupport::s_negativeInfinity =
-DoubleSupport::s_positiveInfinity;
-const double DoubleSupport::s_positiveZero = 0.0;
+
+const DoubleSupport::NumberUnion DoubleSupport::s_positiveZero = { 0.0 };
#if !defined(_AIX)
-const double DoubleSupport::s_negativeZero = -DoubleSupport::s_positiveZero;
+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 double DoubleSupport::s_negativeZero = modf(-7.0, &theDummy);
-#endif
-
-
-typedef DoubleSupport::DWORDPointerType
DWORDPointerType;
-typedef DoubleSupport::UnalignedDWORDPointerType
UnalignedDWORDPointerType;
-
-
-const DWORDPointerType
DoubleSupport::s_NaNFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&s_NaN;
-#else
-
reinterpret_cast<DWORDPointerType>(&s_NaN);
+const DoubleSupport::NumberUnion DoubleSupport::s_negativeZero = {
modf(-7.0, &theDummy) };
#endif
-const UnalignedDWORDPointerType DoubleSupport::s_NaNSecondDWORD
=
- s_NaNFirstDWORD + 1;
-
-
-const DWORDPointerType
DoubleSupport::s_positiveZeroFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&s_positiveZero;
-#else
-
reinterpret_cast<DWORDPointerType>(&s_positiveZero);
-#endif
-
-const UnalignedDWORDPointerType
DoubleSupport::s_positiveZeroSecondDWORD = s_positiveZeroFirstDWORD + 1;
-
-
-const DWORDPointerType
DoubleSupport::s_negativeZeroFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&s_negativeZero;
-#else
-
reinterpret_cast<DWORDPointerType>(&s_negativeZero);
-#endif
-
-const UnalignedDWORDPointerType
DoubleSupport::s_negativeZeroSecondDWORD = s_negativeZeroFirstDWORD + 1;
-
bool
@@ -174,16 +140,6 @@
{
return theLHS == theRHS;
}
-}
-
-
-
-bool
-DoubleSupport::notEqual(
- double theLHS,
- double theRHS)
-{
- return !equal(theLHS, theRHS);
}
1.17 +26 -52 xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp
Index: DoubleSupport.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DoubleSupport.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DoubleSupport.hpp 3 Jan 2003 08:01:29 -0000 1.16
+++ DoubleSupport.hpp 7 Jan 2003 00:42:48 -0000 1.17
@@ -96,19 +96,10 @@
static bool
isNaN(double theNumber)
{
- // Compare the two DWORDs of the double as unsigned longs.
- const DWORDPointerType theFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&theNumber;
-#else
- reinterpret_cast<DWORDPointerType>(&theNumber);
-#endif
-
- const UnalignedDWORDPointerType theSecondDWORD =
- theFirstDWORD + 1;
+ const NumberUnion temp = { theNumber };
- return *theFirstDWORD == *s_NaNFirstDWORD &&
- *theSecondDWORD == *s_NaNSecondDWORD;
+ return s_NaN.dwords.dw1 == temp.dwords.dw1 &&
+ s_NaN.dwords.dw2 == temp.dwords.dw2;
}
/**
@@ -144,19 +135,10 @@
static bool
isPositiveZero(double theNumber)
{
- // Compare the two DWORDs of the double as unsigned longs.
- const DWORDPointerType theFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&theNumber;
-#else
- reinterpret_cast<DWORDPointerType>(&theNumber);
-#endif
+ const NumberUnion temp = { theNumber };
- const UnalignedDWORDPointerType theSecondDWORD =
- theFirstDWORD + 1;
-
- return *theFirstDWORD == *s_positiveZeroFirstDWORD &&
- *theSecondDWORD == *s_positiveZeroSecondDWORD;
+ return s_positiveZero.dwords.dw1 == temp.dwords.dw1 &&
+ s_positiveZero.dwords.dw2 == temp.dwords.dw2;
}
/**
@@ -168,19 +150,10 @@
static bool
isNegativeZero(double theNumber)
{
- // Compare the two DWORDs of the double as unsigned longs.
- const DWORDPointerType theFirstDWORD =
-#if defined(XALAN_OLD_STYLE_CASTS)
- (DWORDPointerType)&theNumber;
-#else
- reinterpret_cast<DWORDPointerType>(&theNumber);
-#endif
-
- const UnalignedDWORDPointerType theSecondDWORD =
- theFirstDWORD + 1;
+ const NumberUnion temp = { theNumber };
- return *theFirstDWORD == *s_negativeZeroFirstDWORD &&
- *theSecondDWORD == *s_negativeZeroSecondDWORD;
+ 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
@@ -196,7 +169,7 @@
static double
getNaN()
{
- return s_NaN;
+ return s_NaN.d;
}
/**
@@ -245,7 +218,10 @@
static bool
notEqual(
double theLHS,
- double theRHS);
+ double theRHS)
+ {
+ return !equal(theLHS, theRHS);
+ }
/**
* Compare two double values, taking into account
@@ -642,25 +618,23 @@
#endif
}
- typedef const unsigned int*
DWORDPointerType;
- typedef XALAN_UNALIGNED const unsigned int*
UnalignedDWORDPointerType;
+ typedef union
+ {
+ double d;
+ struct
+ {
+ unsigned int dw1;
+ unsigned int dw2;
+ } dwords;
+ } NumberUnion;
private:
- static const double s_NaN;
+ static const NumberUnion s_NaN;
static const double s_positiveInfinity;
static const double s_negativeInfinity;
- static const double s_positiveZero;
- static const double s_negativeZero;
-
- static const DWORDPointerType s_NaNFirstDWORD;
- static const UnalignedDWORDPointerType s_NaNSecondDWORD;
-
- static const DWORDPointerType
s_positiveZeroFirstDWORD;
- static const UnalignedDWORDPointerType s_positiveZeroSecondDWORD;
-
- static const DWORDPointerType
s_negativeZeroFirstDWORD;
- static const UnalignedDWORDPointerType s_negativeZeroSecondDWORD;
+ static const NumberUnion s_positiveZero;
+ static const NumberUnion s_negativeZero;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]