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...@apache.org on 2001/02/01 19:31:28 UTC
cvs commit: xml-xalan/c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp
dbertoni 01/02/01 10:31:27
Modified: c/src/PlatformSupport DoubleSupport.cpp DoubleSupport.hpp
Log:
Moved rounding function from XPath/FunctionRound to here.
Revision Changes Path
1.19 +45 -0 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DoubleSupport.cpp 2001/01/16 02:42:13 1.18
+++ DoubleSupport.cpp 2001/02/01 18:31:25 1.19
@@ -883,3 +883,48 @@
}
#endif
+
+
+double
+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;
+
+ const double fracPart = modf(theValue, &intPart);
+
+ 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.11 +10 -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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DoubleSupport.hpp 2001/01/16 02:42:13 1.10
+++ DoubleSupport.hpp 2001/02/01 18:31:26 1.11
@@ -593,6 +593,16 @@
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);
+
private:
static const double s_NaN;