Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.9

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

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 // A class to help us support IEEE 754.
00040 class XALAN_PLATFORMSUPPORT_EXPORT DoubleSupport
00041 {
00042 public:
00043 
00047     static void
00048     initialize(MemoryManagerType&      theManager);
00049  
00053     static void
00054     terminate();
00055 
00056 
00057     // Use these functions to determine if a value represents one of these
00058     // specia values.  On some platforms, regular C/C++ operators don't work
00059     // as we need them too, so we have these helper functions.
00060 
00067     static bool
00068     isNaN(double    theNumber)
00069     {
00070         return s_NaN == theNumber;
00071     }
00072 
00079     static bool
00080     isPositiveInfinity(double   theNumber)
00081     {
00082         return s_positiveInfinity == theNumber;
00083     }
00084 
00091     static bool
00092     isNegativeInfinity(double   theNumber)
00093     {
00094         return s_negativeInfinity == theNumber;
00095     }
00096 
00103     static bool
00104     isPositiveZero(double   theNumber)
00105     {
00106         return s_positiveZero == theNumber;
00107     }
00108 
00115     static bool
00116     isNegativeZero(double   theNumber)
00117     {
00118         return s_negativeZero == theNumber;
00119     }
00120 
00121     // These can be used to initialize values, but should not
00122     // be used to do equality comparisons, as == may fail on
00123     // some platforms.
00124     //
00125 
00131     static double
00132     getNaN()
00133     {
00134         return s_NaN.d;
00135     }
00136 
00142     static double
00143     getPositiveInfinity()
00144     {
00145         return s_positiveInfinity.d;
00146     }
00147 
00153     static double
00154     getNegativeInfinity()
00155     {
00156         return s_negativeInfinity.d;
00157     }
00158 
00167     static bool
00168     equal(
00169             double  theLHS,
00170             double  theRHS);
00171 
00180     static bool
00181     notEqual(
00182             double  theLHS,
00183             double  theRHS)
00184     {
00185         return !equal(theLHS, theRHS);
00186     }
00187 
00196     static bool
00197     lessThan(
00198             double  theLHS,
00199             double  theRHS);
00200 
00209     static bool
00210     lessThanOrEqual(
00211             double  theLHS,
00212             double  theRHS);
00213 
00222     static bool
00223     greaterThan(
00224             double  theLHS,
00225             double  theRHS);
00226 
00235     static bool
00236     greaterThanOrEqual(
00237             double  theLHS,
00238             double  theRHS);
00239 
00248     static double
00249     add(
00250             double  theLHS,
00251             double  theRHS);
00252 
00261     static double
00262     subtract(
00263             double  theLHS,
00264             double  theRHS);
00265 
00274     static double
00275     multiply(
00276             double  theLHS,
00277             double  theRHS);
00278 
00287     static double
00288     divide(
00289             double  theLHS,
00290             double  theRHS);
00291 
00301     static double
00302     modulus(
00303             double  theLHS,
00304             double  theRHS);
00305 
00314     static double
00315     negative(double theDouble);
00316 
00317     // Some functors to do the same thing.  This is for
00318     // STL integration...
00319     #if defined(XALAN_NO_STD_NAMESPACE)
00320     struct equalFunction : public binary_function<const double&, const double&, bool>
00321     #else
00322     struct equalFunction : public std::binary_function<const double&, const double&, bool>
00323     #endif
00324     {
00325         result_type
00326         operator()(
00327             first_argument_type     theLHS,
00328             second_argument_type    theRHS) const
00329         {
00330             return equal(theLHS, theRHS);
00331         }
00332     };
00333 
00334     #if defined(XALAN_NO_STD_NAMESPACE)
00335     struct notEqualFunction : public binary_function<const double&, const double&, bool>
00336     #else
00337     struct notEqualFunction : 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 notEqual(theLHS, theRHS);
00346         }
00347     };
00348 
00349     #if defined(XALAN_NO_STD_NAMESPACE)
00350     struct lessThanFunction : public binary_function<const double&, const double&, bool>
00351     #else
00352     struct lessThanFunction : 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 lessThan(theLHS, theRHS);
00361         }
00362     };
00363 
00364     #if defined(XALAN_NO_STD_NAMESPACE)
00365     struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00366     #else
00367     struct lessThanOrEqualFunction : 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 lessThanOrEqual(theLHS, theRHS);
00376         }
00377     };
00378 
00379     #if defined(XALAN_NO_STD_NAMESPACE)
00380     struct greaterThanFunction : public binary_function<const double&, const double&, bool>
00381     #else
00382     struct greaterThanFunction : 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 greaterThan(theLHS, theRHS);
00391         }
00392     };
00393 
00394     #if defined(XALAN_NO_STD_NAMESPACE)
00395     struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00396     #else
00397     struct greaterThanOrEqualFunction : 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 greaterThanOrEqual(theLHS, theRHS);
00406         }
00407     };
00408 
00409     #if defined(XALAN_NO_STD_NAMESPACE)
00410     struct addFunction : public binary_function<const double&, const double&, double>
00411     #else
00412     struct addFunction : public std::binary_function<const double&, const double&, double>
00413     #endif
00414     {
00415         result_type
00416         operator()(
00417             first_argument_type     theLHS,
00418             second_argument_type    theRHS) const
00419         {
00420             return add(theLHS, theRHS);
00421         }
00422     };
00423 
00424     #if defined(XALAN_NO_STD_NAMESPACE)
00425     struct subtractFunction : public binary_function<const double&, const double&, double>
00426     #else
00427     struct subtractFunction : 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 subtract(theLHS, theRHS);
00436         }
00437     };
00438 
00439     #if defined(XALAN_NO_STD_NAMESPACE)
00440     struct multiplyFunction : public binary_function<const double&, const double&, double>
00441     #else
00442     struct multiplyFunction : 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 multiply(theLHS, theRHS);
00451         }
00452     };
00453 
00454     #if defined(XALAN_NO_STD_NAMESPACE)
00455     struct divideFunction : public binary_function<const double&, const double&, double>
00456     #else
00457     struct divideFunction : 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 divide(theLHS, theRHS);
00466         }
00467     };
00468 
00469     #if defined(XALAN_NO_STD_NAMESPACE)
00470     struct modulusFunction : public binary_function<const double&, const double&, double>
00471     #else
00472     struct modulusFunction : 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 modulus(theLHS, theRHS);
00481         }
00482     };
00483 
00484     #if defined(XALAN_NO_STD_NAMESPACE)
00485     struct negativeFunction : public unary_function<const double&, double>
00486     #else
00487     struct negativeFunction : public std::unary_function<const double&, double>
00488     #endif
00489     {
00490         result_type
00491         operator()(argument_type    theDouble) const
00492         {
00493             return negative(theDouble);
00494         }
00495     };
00496 
00504     static bool
00505     isValid(const XalanDOMString&   theString);
00506 
00514     static bool
00515     isValid(const XalanDOMChar*     theString);
00516 
00525     static double
00526     toDouble(const XalanDOMString&  theString, MemoryManagerType&      theManager);
00527 
00536     static double
00537     toDouble(const XalanDOMChar*    theString, MemoryManagerType&      theManager);
00538 
00546     static double
00547     round(double    theValue);
00548 
00556     static double
00557     ceiling(double  theValue)
00558     {
00559 #if defined(XALAN_STRICT_ANSI_HEADERS)
00560         return std::ceil(theValue);
00561 #else
00562         return ceil(theValue);
00563 #endif
00564     }
00565 
00573     static double
00574     floor(double    theValue)
00575     {
00576 #if defined(XALAN_STRICT_ANSI_HEADERS)
00577         return std::floor(theValue);
00578 #else
00579         return ::floor(theValue);
00580 #endif
00581     }
00582 
00583     typedef union
00584     {
00585         double  d;
00586         struct
00587         {
00588             unsigned int    dw1;
00589             unsigned int    dw2;
00590         } dwords;
00591 
00592         bool
00593         operator==(double   theNumber) const
00594         {
00595             const NumberUnion   temp = { theNumber };
00596 
00597             return dwords.dw1 == temp.dwords.dw1 &&
00598                    dwords.dw2 == temp.dwords.dw2;
00599         }
00600 
00601     } NumberUnion;
00602 
00603 private:
00604 
00605     static NumberUnion          s_NaN;
00606     static const NumberUnion    s_positiveInfinity;
00607     static const NumberUnion    s_negativeInfinity;
00608     static const NumberUnion    s_positiveZero;
00609     static const NumberUnion    s_negativeZero;
00610 };
00611 
00612 
00613 
00614 XALAN_CPP_NAMESPACE_END
00615 
00616 
00617 
00618 #endif  // DOUBLESUPPORT_HEADER_GUARD_1357924680

Interpreting class diagrams

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

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