Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DoubleSupport.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #if !defined(DOUBLESUPPORT_HEADER_GUARD_1357924680)
00017 #define DOUBLESUPPORT_HEADER_GUARD_1357924680
00018 
00019 
00020 
00021 // Base include file.  Must be first.
00022 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp>
00023 
00024 
00025 
00026 #include <cmath>
00027 #include <functional>
00028 
00029 
00030 
00031 #include <xalanc/XalanDOM/XalanDOMString.hpp>
00032 
00033 
00034 
00035 XALAN_CPP_NAMESPACE_BEGIN
00036 
00037 
00038 
00039 XALAN_USING_XERCES(MemoryManager)
00040 
00041 
00042 
00043 // A class to help us support IEEE 754.
00044 class XALAN_PLATFORMSUPPORT_EXPORT DoubleSupport
00045 {
00046 public:
00047 
00052     static void
00053     initialize();
00054  
00058     static void
00059     terminate();
00060 
00061 
00062     // Use these functions to determine if a value represents one of these
00063     // specia values.  On some platforms, regular C/C++ operators don't work
00064     // as we need them too, so we have these helper functions.
00065 
00072     static bool
00073     isNaN(double    theNumber)
00074     {
00075         return s_NaN == theNumber;
00076     }
00077 
00084     static bool
00085     isPositiveInfinity(double   theNumber)
00086     {
00087         return s_positiveInfinity == theNumber;
00088     }
00089 
00096     static bool
00097     isNegativeInfinity(double   theNumber)
00098     {
00099         return s_negativeInfinity == theNumber;
00100     }
00101 
00108     static bool
00109     isPositiveZero(double   theNumber)
00110     {
00111         return s_positiveZero == theNumber;
00112     }
00113 
00120     static bool
00121     isNegativeZero(double   theNumber)
00122     {
00123         return s_negativeZero == theNumber;
00124     }
00125 
00126     // These can be used to initialize values, but should not
00127     // be used to do equality comparisons, as == may fail on
00128     // some platforms.
00129     //
00130 
00136     static double
00137     getNaN()
00138     {
00139         return s_NaN.d;
00140     }
00141 
00147     static double
00148     getPositiveInfinity()
00149     {
00150         return s_positiveInfinity.d;
00151     }
00152 
00158     static double
00159     getNegativeInfinity()
00160     {
00161         return s_negativeInfinity.d;
00162     }
00163 
00172     static bool
00173     equal(
00174             double  theLHS,
00175             double  theRHS);
00176 
00185     static bool
00186     notEqual(
00187             double  theLHS,
00188             double  theRHS)
00189     {
00190         return !equal(theLHS, theRHS);
00191     }
00192 
00201     static bool
00202     lessThan(
00203             double  theLHS,
00204             double  theRHS);
00205 
00214     static bool
00215     lessThanOrEqual(
00216             double  theLHS,
00217             double  theRHS);
00218 
00227     static bool
00228     greaterThan(
00229             double  theLHS,
00230             double  theRHS);
00231 
00240     static bool
00241     greaterThanOrEqual(
00242             double  theLHS,
00243             double  theRHS);
00244 
00253     static double
00254     add(
00255             double  theLHS,
00256             double  theRHS);
00257 
00266     static double
00267     subtract(
00268             double  theLHS,
00269             double  theRHS);
00270 
00279     static double
00280     multiply(
00281             double  theLHS,
00282             double  theRHS);
00283 
00292     static double
00293     divide(
00294             double  theLHS,
00295             double  theRHS);
00296 
00306     static double
00307     modulus(
00308             double  theLHS,
00309             double  theRHS);
00310 
00319     static double
00320     negative(double theDouble);
00321 
00329     static double
00330     abs(double theDouble);
00331 
00332     // Some functors to do the same thing.  This is for
00333     // STL integration...
00334     #if defined(XALAN_NO_STD_NAMESPACE)
00335     struct equalFunction : public binary_function<const double&, const double&, bool>
00336     #else
00337     struct equalFunction : public std::binary_function<const double&, const double&, bool>
00338     #endif
00339     {
00340         result_type
00341         operator()(
00342             first_argument_type     theLHS,
00343             second_argument_type    theRHS) const
00344         {
00345             return equal(theLHS, theRHS);
00346         }
00347     };
00348 
00349     #if defined(XALAN_NO_STD_NAMESPACE)
00350     struct notEqualFunction : public binary_function<const double&, const double&, bool>
00351     #else
00352     struct notEqualFunction : public std::binary_function<const double&, const double&, bool>
00353     #endif
00354     {
00355         result_type
00356         operator()(
00357             first_argument_type     theLHS,
00358             second_argument_type    theRHS) const
00359         {
00360             return notEqual(theLHS, theRHS);
00361         }
00362     };
00363 
00364     #if defined(XALAN_NO_STD_NAMESPACE)
00365     struct lessThanFunction : public binary_function<const double&, const double&, bool>
00366     #else
00367     struct lessThanFunction : public std::binary_function<const double&, const double&, bool>
00368     #endif
00369     {
00370         result_type
00371         operator()(
00372             first_argument_type     theLHS,
00373             second_argument_type    theRHS) const
00374         {
00375             return lessThan(theLHS, theRHS);
00376         }
00377     };
00378 
00379     #if defined(XALAN_NO_STD_NAMESPACE)
00380     struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00381     #else
00382     struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00383     #endif
00384     {
00385         result_type
00386         operator()(
00387             first_argument_type     theLHS,
00388             second_argument_type    theRHS) const
00389         {
00390             return lessThanOrEqual(theLHS, theRHS);
00391         }
00392     };
00393 
00394     #if defined(XALAN_NO_STD_NAMESPACE)
00395     struct greaterThanFunction : public binary_function<const double&, const double&, bool>
00396     #else
00397     struct greaterThanFunction : public std::binary_function<const double&, const double&, bool>
00398     #endif
00399     {
00400         result_type
00401         operator()(
00402             first_argument_type     theLHS,
00403             second_argument_type    theRHS) const
00404         {
00405             return greaterThan(theLHS, theRHS);
00406         }
00407     };
00408 
00409     #if defined(XALAN_NO_STD_NAMESPACE)
00410     struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00411     #else
00412     struct greaterThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00413     #endif
00414     {
00415         result_type
00416         operator()(
00417             first_argument_type     theLHS,
00418             second_argument_type    theRHS) const
00419         {
00420             return greaterThanOrEqual(theLHS, theRHS);
00421         }
00422     };
00423 
00424     #if defined(XALAN_NO_STD_NAMESPACE)
00425     struct addFunction : public binary_function<const double&, const double&, double>
00426     #else
00427     struct addFunction : public std::binary_function<const double&, const double&, double>
00428     #endif
00429     {
00430         result_type
00431         operator()(
00432             first_argument_type     theLHS,
00433             second_argument_type    theRHS) const
00434         {
00435             return add(theLHS, theRHS);
00436         }
00437     };
00438 
00439     #if defined(XALAN_NO_STD_NAMESPACE)
00440     struct subtractFunction : public binary_function<const double&, const double&, double>
00441     #else
00442     struct subtractFunction : public std::binary_function<const double&, const double&, double>
00443     #endif
00444     {
00445         result_type
00446         operator()(
00447             first_argument_type     theLHS,
00448             second_argument_type    theRHS) const
00449         {
00450             return subtract(theLHS, theRHS);
00451         }
00452     };
00453 
00454     #if defined(XALAN_NO_STD_NAMESPACE)
00455     struct multiplyFunction : public binary_function<const double&, const double&, double>
00456     #else
00457     struct multiplyFunction : public std::binary_function<const double&, const double&, double>
00458     #endif
00459     {
00460         result_type
00461         operator()(
00462             first_argument_type     theLHS,
00463             second_argument_type    theRHS) const
00464         {
00465             return multiply(theLHS, theRHS);
00466         }
00467     };
00468 
00469     #if defined(XALAN_NO_STD_NAMESPACE)
00470     struct divideFunction : public binary_function<const double&, const double&, double>
00471     #else
00472     struct divideFunction : public std::binary_function<const double&, const double&, double>
00473     #endif
00474     {
00475         result_type
00476         operator()(
00477             first_argument_type     theLHS,
00478             second_argument_type    theRHS) const
00479         {
00480             return divide(theLHS, theRHS);
00481         }
00482     };
00483 
00484     #if defined(XALAN_NO_STD_NAMESPACE)
00485     struct modulusFunction : public binary_function<const double&, const double&, double>
00486     #else
00487     struct modulusFunction : public std::binary_function<const double&, const double&, double>
00488     #endif
00489     {
00490         result_type
00491         operator()(
00492             first_argument_type     theLHS,
00493             second_argument_type    theRHS) const
00494         {
00495             return modulus(theLHS, theRHS);
00496         }
00497     };
00498 
00499     #if defined(XALAN_NO_STD_NAMESPACE)
00500     struct negativeFunction : public unary_function<const double&, double>
00501     #else
00502     struct negativeFunction : public std::unary_function<const double&, double>
00503     #endif
00504     {
00505         result_type
00506         operator()(argument_type    theDouble) const
00507         {
00508             return negative(theDouble);
00509         }
00510     };
00511 
00519     static bool
00520     isValid(const XalanDOMString&   theString);
00521 
00529     static bool
00530     isValid(const XalanDOMChar*     theString);
00531 
00541     static double
00542     toDouble(
00543             const XalanDOMString&   theString,
00544             MemoryManager&          theManager);
00545 
00555     static double
00556     toDouble(
00557             const XalanDOMChar*     theString,
00558             MemoryManager&          theManager);
00559 
00567     static double
00568     round(double    theValue);
00569 
00577     static double
00578     ceiling(double  theValue)
00579     {
00580 #if defined(XALAN_STRICT_ANSI_HEADERS)
00581         return std::ceil(theValue);
00582 #else
00583         return ceil(theValue);
00584 #endif
00585     }
00586 
00594     static double
00595     floor(double    theValue)
00596     {
00597 #if defined(XALAN_STRICT_ANSI_HEADERS)
00598         return std::floor(theValue);
00599 #else
00600         return ::floor(theValue);
00601 #endif
00602     }
00603 
00604     typedef union
00605     {
00606         double  d;
00607         struct
00608         {
00609             unsigned int    dw1;
00610             unsigned int    dw2;
00611         } dwords;
00612 
00613         bool
00614         operator==(double   theNumber) const
00615         {
00616             const NumberUnion   temp = { theNumber };
00617 
00618             return dwords.dw1 == temp.dwords.dw1 &&
00619                    dwords.dw2 == temp.dwords.dw2;
00620         }
00621 
00622     } NumberUnion;
00623 
00624 private:
00625 
00626 #if defined(XALAN_NO_STD_NUMERIC_LIMITS)
00627     static NumberUnion          s_NaN;
00628 #else
00629     static const NumberUnion    s_NaN;
00630 #endif
00631 
00632     static const NumberUnion    s_positiveInfinity;
00633     static const NumberUnion    s_negativeInfinity;
00634     static const NumberUnion    s_positiveZero;
00635     static const NumberUnion    s_negativeZero;
00636 };
00637 
00638 
00639 
00640 XALAN_CPP_NAMESPACE_END
00641 
00642 
00643 
00644 #endif  // DOUBLESUPPORT_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo