You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/12/01 22:36:01 UTC

cvs commit: xml-xalan/c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp

dbertoni    00/12/01 13:36:01

  Modified:    c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp
  Log:
  Special support code for positive and negative infinity.
  
  Revision  Changes    Path
  1.17      +26 -10    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DoubleSupport.cpp	2000/11/29 21:48:34	1.16
  +++ DoubleSupport.cpp	2000/12/01 21:36:00	1.17
  @@ -70,6 +70,8 @@
   const double	DoubleSupport::s_NaN = sqrt(-2.01);
   const double	DoubleSupport::s_positiveInfinity = HUGE_VAL;
   const double	DoubleSupport::s_negativeInfinity = -DoubleSupport::s_positiveInfinity;
  +const double	DoubleSupport::s_positiveZero = 0.0;
  +const double	DoubleSupport::s_negativeZero = -DoubleSupport::s_positiveZero;
   
   
   
  @@ -84,7 +86,27 @@
   					s_NaNFirstDWORD + 1;
   
   
  +const unsigned long*	DoubleSupport::s_positiveZeroFirstDWORD =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +					(const unsigned long*)&s_positiveZero;
  +#else
  +					reinterpret_cast<const unsigned long*>(&s_positiveZero);
  +#endif
  +
  +const unsigned long*	DoubleSupport::s_positiveZeroSecondDWORD = s_positiveZeroFirstDWORD + 1;
  +
  +
  +const unsigned long*	DoubleSupport::s_negativeZeroFirstDWORD =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +					(const unsigned long*)&s_negativeZero;
  +#else
  +					reinterpret_cast<const unsigned long*>(&s_negativeZero);
  +#endif
  +
  +const unsigned long*	DoubleSupport::s_negativeZeroSecondDWORD = s_negativeZeroFirstDWORD + 1;
   
  +
  +
   bool
   DoubleSupport::equal(
   			double	theLHS,
  @@ -107,14 +129,7 @@
   			double	theLHS,
   			double	theRHS)
   {
  -	if (isNaN(theLHS) == true || isNaN(theRHS) == true)
  -	{
  -		return true;
  -	}
  -	else
  -	{
  -		return theLHS != theRHS;
  -	}
  +	return !equal(theLHS, theRHS);
   }
   
   
  @@ -276,14 +291,15 @@
   			// This is NaN...
   			return DoubleSupport::getNaN();
   		}
  -		else if (theLHS > 0.0L)
  +		else if (theLHS > 0.0L &&
  +				 isPositiveZero(theRHS) == true)
   		{
   			// This is positive infinity...
   			return DoubleSupport::getPositiveInfinity();
   		}
   		else
   		{
  -			// This is positive infinity...
  +			// This is negative infinity...
   			return DoubleSupport::getNegativeInfinity();
   		}
   	}
  
  
  
  1.9       +56 -0     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DoubleSupport.hpp	2000/10/02 16:28:10	1.8
  +++ DoubleSupport.hpp	2000/12/01 21:36:00	1.9
  @@ -130,6 +130,54 @@
   		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)
  +	{
  +		// Compare the two DWORDs of the double as unsigned longs.
  +		const unsigned long* const	theFirstDWORD =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +			(const unsigned long*)&theNumber;
  +#else
  +			reinterpret_cast<const unsigned long*>(&theNumber);
  +#endif
  +
  +		const unsigned long* const	theSecondDWORD =
  +							theFirstDWORD + 1;
  +
  +		return *theFirstDWORD == *s_positiveZeroFirstDWORD &&
  +			   *theSecondDWORD == *s_positiveZeroSecondDWORD;
  +	}
  +
  +	/**
  +	 * 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)
  +	{
  +		// Compare the two DWORDs of the double as unsigned longs.
  +		const unsigned long* const	theFirstDWORD =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +			(const unsigned long*)&theNumber;
  +#else
  +			reinterpret_cast<const unsigned long*>(&theNumber);
  +#endif
  +
  +		const unsigned long* const	theSecondDWORD =
  +							theFirstDWORD + 1;
  +
  +		return *theFirstDWORD == *s_negativeZeroFirstDWORD &&
  +			   *theSecondDWORD == *s_negativeZeroSecondDWORD;
  +	}
  +
   	// These can be used to initialize values, but should not
   	// be used to do equality comparisons, as == may fail on
   	// some platforms.
  @@ -514,9 +562,17 @@
   	static const double				s_NaN;
   	static const double				s_positiveInfinity;
   	static const double				s_negativeInfinity;
  +	static const double				s_positiveZero;
  +	static const double				s_negativeZero;
   
   	static const unsigned long*		s_NaNFirstDWORD;
   	static const unsigned long*		s_NaNSecondDWORD;
  +
  +	static const unsigned long*		s_positiveZeroFirstDWORD;
  +	static const unsigned long*		s_positiveZeroSecondDWORD;
  +
  +	static const unsigned long*		s_negativeZeroFirstDWORD;
  +	static const unsigned long*		s_negativeZeroSecondDWORD;
   };