xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbert...@apache.org
Subject cvs commit: xml-xalan/c/src/xalanc/PlatformSupport DoubleSupport.cpp
Date Wed, 11 May 2005 00:13:35 GMT
dbertoni    2005/05/10 17:13:35

  Modified:    c/src/xalanc/PlatformSupport DoubleSupport.cpp
  Log:
  Fix for Jira issue XALANC-509.
  
  Revision  Changes    Path
  1.8       +38 -7     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DoubleSupport.cpp	29 Apr 2005 21:39:42 -0000	1.7
  +++ DoubleSupport.cpp	11 May 2005 00:13:35 -0000	1.8
  @@ -687,6 +687,23 @@
   
   
   
  +inline double
  +modfRound(double  theValue)
  +{
  +    double          intPart = 0;
  +
  +    const double    fracPart =
  +#if defined(XALAN_STRICT_ANSI_HEADERS)
  +        std::modf(theValue + 0.5, &intPart);
  +#else
  +        modf(theValue + 0.5, &intPart);
  +#endif
  +
  +    return intPart;
  +}
  +
  +
  +
   double
   DoubleSupport::round(double     theValue)
   {
  @@ -708,7 +725,16 @@
       }
       else if (theValue > 0)
       {
  -        return long(theValue + 0.5);
  +        // If the value is less than the maximum value for
  +        // a long, this is the fastest way to do it.
  +        if (theValue < LONG_MAX)
  +        {
  +            return long(theValue + 0.5);
  +        }
  +        else
  +        {
  +            return modfRound(theValue);
  +        }
       }
       else
       {
  @@ -717,20 +743,25 @@
           // round up (toward 0), rather than down.
           double          intPart = 0;
   
  +        const double    fracPart = 
   #if defined(XALAN_STRICT_ANSI_HEADERS)
  -        const double    fracPart = std::modf(theValue, &intPart);
  +            std::modf(theValue, &intPart);
   #else
  -        const double    fracPart = modf(theValue, &intPart);
  +            modf(theValue, &intPart);
   #endif
   
  -        if (fracPart == -0.5)
  +        const double    theAdjustedValue =
  +            fracPart == -0.5 ? theValue + 0.5 : theValue - 0.5;
  +
  +        // If the value is greater than the minimum value for
  +        // a long, this is the fastest way to do it.
  +        if (theAdjustedValue > LONG_MIN)
           {
  -            // special case -- we have have to round toward 0...
  -            return long(theValue + 0.5);
  +            return long(theAdjustedValue);
           }
           else
           {
  -            return long(theValue - 0.5);
  +            return modfRound(theAdjustedValue);
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message