Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@www.apache.org Received: (qmail 16150 invoked from network); 11 May 2005 00:13:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 May 2005 00:13:37 -0000 Received: (qmail 77948 invoked by uid 500); 11 May 2005 00:17:12 -0000 Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 77930 invoked by uid 500); 11 May 2005 00:17:12 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: List-Id: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 77912 invoked by uid 99); 11 May 2005 00:17:11 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 10 May 2005 17:17:11 -0700 Received: (qmail 16138 invoked by uid 1034); 11 May 2005 00:13:35 -0000 Date: 11 May 2005 00:13:35 -0000 Message-ID: <20050511001335.16137.qmail@minotaur.apache.org> From: dbertoni@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/c/src/xalanc/PlatformSupport DoubleSupport.cpp X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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