Xalan-C++ API Documentation

The Xalan C++ XSL Transformer Version 1.1

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  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "Xalan" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 1999, International
00053  * Business Machines, Inc., http://www.ibm.com.  For more
00054  * information on the Apache Software Foundation, please see
00055  * <http://www.apache.org/>.
00056  */
00057 #if !defined(DOUBLESUPPORT_HEADER_GUARD_1357924680)
00058 #define DOUBLESUPPORT_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 // Base include file.  Must be first.
00063 #include <PlatformSupport/PlatformSupportDefinitions.hpp>
00064 
00065 
00066 
00067 #include <functional>
00068 
00069 
00070 
00071 #include <XalanDOM/XalanDOMString.hpp>
00072 
00073 
00074 
00075 // A class to help us support IEEE 754.
00076 class XALAN_PLATFORMSUPPORT_EXPORT DoubleSupport
00077 {
00078 public:
00079 
00080     // Use these functions to determine if a value represents one of these
00081     // values.  It seems that under some architectures, NaN will compare
00082     // as equal to any number, which is a big problem.  Hence these helper
00083     // functions.
00084 
00091     static bool
00092     isNaN(double    theNumber)
00093     {
00094         // Compare the two DWORDs of the double as unsigned longs.
00095         const DWORDPointerType  theFirstDWORD =
00096 #if defined(XALAN_OLD_STYLE_CASTS)
00097             (DWORDPointerType)&theNumber;
00098 #else
00099             reinterpret_cast<DWORDPointerType>(&theNumber);
00100 #endif
00101 
00102         const UnalignedDWORDPointerType     theSecondDWORD =
00103                             theFirstDWORD + 1;
00104 
00105         return *theFirstDWORD == *s_NaNFirstDWORD &&
00106                *theSecondDWORD == *s_NaNSecondDWORD;
00107     }
00108 
00115     static bool
00116     isPositiveInfinity(double   theNumber)
00117     {
00118         return !isNaN(theNumber) && theNumber == s_positiveInfinity;
00119     }
00120 
00127     static bool
00128     isNegativeInfinity(double   theNumber)
00129     {
00130         return !isNaN(theNumber) && theNumber == s_negativeInfinity;
00131     }
00132 
00139     static bool
00140     isPositiveZero(double   theNumber)
00141     {
00142         // Compare the two DWORDs of the double as unsigned longs.
00143         const DWORDPointerType  theFirstDWORD =
00144 #if defined(XALAN_OLD_STYLE_CASTS)
00145             (DWORDPointerType)&theNumber;
00146 #else
00147             reinterpret_cast<DWORDPointerType>(&theNumber);
00148 #endif
00149 
00150         const UnalignedDWORDPointerType     theSecondDWORD =
00151                             theFirstDWORD + 1;
00152 
00153         return *theFirstDWORD == *s_positiveZeroFirstDWORD &&
00154                *theSecondDWORD == *s_positiveZeroSecondDWORD;
00155     }
00156 
00163     static bool
00164     isNegativeZero(double   theNumber)
00165     {
00166         // Compare the two DWORDs of the double as unsigned longs.
00167         const DWORDPointerType  theFirstDWORD =
00168 #if defined(XALAN_OLD_STYLE_CASTS)
00169             (DWORDPointerType)&theNumber;
00170 #else
00171             reinterpret_cast<DWORDPointerType>(&theNumber);
00172 #endif
00173 
00174         const UnalignedDWORDPointerType     theSecondDWORD =
00175                             theFirstDWORD + 1;
00176 
00177         return *theFirstDWORD == *s_negativeZeroFirstDWORD &&
00178                *theSecondDWORD == *s_negativeZeroSecondDWORD;
00179     }
00180 
00181     // These can be used to initialize values, but should not
00182     // be used to do equality comparisons, as == may fail on
00183     // some platforms.
00184     //
00185 
00191     static double
00192     getNaN()
00193     {
00194         return s_NaN;
00195     }
00196 
00202     static double
00203     getPositiveInfinity()
00204     {
00205         return s_positiveInfinity;
00206     }
00207 
00213     static double
00214     getNegativeInfinity()
00215     {
00216         return s_negativeInfinity;
00217     }
00218 
00227     static bool
00228     equal(
00229             double  theLHS,
00230             double  theRHS);
00231 
00240     static bool
00241     notEqual(
00242             double  theLHS,
00243             double  theRHS);
00244 
00253     static bool
00254     lessThan(
00255             double  theLHS,
00256             double  theRHS);
00257 
00266     static bool
00267     lessThanOrEqual(
00268             double  theLHS,
00269             double  theRHS);
00270 
00279     static bool
00280     greaterThan(
00281             double  theLHS,
00282             double  theRHS);
00283 
00292     static bool
00293     greaterThanOrEqual(
00294             double  theLHS,
00295             double  theRHS);
00296 
00305     static double
00306     add(
00307             double  theLHS,
00308             double  theRHS);
00309 
00318     static double
00319     subtract(
00320             double  theLHS,
00321             double  theRHS);
00322 
00331     static double
00332     multiply(
00333             double  theLHS,
00334             double  theRHS);
00335 
00344     static double
00345     divide(
00346             double  theLHS,
00347             double  theRHS);
00348 
00358     static double
00359     modulus(
00360             double  theLHS,
00361             double  theRHS);
00362 
00371     static double
00372     negative(double theDouble);
00373 
00374     // Some functors to do the same thing.  This is for
00375     // STL integration...
00376     #if defined(XALAN_NO_NAMESPACES)
00377     struct equalFunction : public binary_function<const double&, const double&, bool>
00378     #else
00379     struct equalFunction : public std::binary_function<const double&, const double&, bool>
00380     #endif
00381     {
00382         result_type
00383         operator()(
00384             first_argument_type     theLHS,
00385             second_argument_type    theRHS) const
00386         {
00387             return equal(theLHS, theRHS);
00388         }
00389     };
00390 
00391     #if defined(XALAN_NO_NAMESPACES)
00392     struct notEqualFunction : public binary_function<const double&, const double&, bool>
00393     #else
00394     struct notEqualFunction : public std::binary_function<const double&, const double&, bool>
00395     #endif
00396     {
00397         result_type
00398         operator()(
00399             first_argument_type     theLHS,
00400             second_argument_type    theRHS) const
00401         {
00402             return notEqual(theLHS, theRHS);
00403         }
00404     };
00405 
00406     #if defined(XALAN_NO_NAMESPACES)
00407     struct lessThanFunction : public binary_function<const double&, const double&, bool>
00408     #else
00409     struct lessThanFunction : public std::binary_function<const double&, const double&, bool>
00410     #endif
00411     {
00412         result_type
00413         operator()(
00414             first_argument_type     theLHS,
00415             second_argument_type    theRHS) const
00416         {
00417             return lessThan(theLHS, theRHS);
00418         }
00419     };
00420 
00421     #if defined(XALAN_NO_NAMESPACES)
00422     struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00423     #else
00424     struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00425     #endif
00426     {
00427         result_type
00428         operator()(
00429             first_argument_type     theLHS,
00430             second_argument_type    theRHS) const
00431         {
00432             return lessThanOrEqual(theLHS, theRHS);
00433         }
00434     };
00435 
00436     #if defined(XALAN_NO_NAMESPACES)
00437     struct greaterThanFunction : public binary_function<const double&, const double&, bool>
00438     #else
00439     struct greaterThanFunction : public std::binary_function<const double&, const double&, bool>
00440     #endif
00441     {
00442         result_type
00443         operator()(
00444             first_argument_type     theLHS,
00445             second_argument_type    theRHS) const
00446         {
00447             return greaterThan(theLHS, theRHS);
00448         }
00449     };
00450 
00451     #if defined(XALAN_NO_NAMESPACES)
00452     struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00453     #else
00454     struct greaterThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00455     #endif
00456     {
00457         result_type
00458         operator()(
00459             first_argument_type     theLHS,
00460             second_argument_type    theRHS) const
00461         {
00462             return greaterThanOrEqual(theLHS, theRHS);
00463         }
00464     };
00465 
00466     #if defined(XALAN_NO_NAMESPACES)
00467     struct addFunction : public binary_function<const double&, const double&, double>
00468     #else
00469     struct addFunction : public std::binary_function<const double&, const double&, double>
00470     #endif
00471     {
00472         result_type
00473         operator()(
00474             first_argument_type     theLHS,
00475             second_argument_type    theRHS) const
00476         {
00477             return add(theLHS, theRHS);
00478         }
00479     };
00480 
00481     #if defined(XALAN_NO_NAMESPACES)
00482     struct subtractFunction : public binary_function<const double&, const double&, double>
00483     #else
00484     struct subtractFunction : public std::binary_function<const double&, const double&, double>
00485     #endif
00486     {
00487         result_type
00488         operator()(
00489             first_argument_type     theLHS,
00490             second_argument_type    theRHS) const
00491         {
00492             return subtract(theLHS, theRHS);
00493         }
00494     };
00495 
00496     #if defined(XALAN_NO_NAMESPACES)
00497     struct multiplyFunction : public binary_function<const double&, const double&, double>
00498     #else
00499     struct multiplyFunction : public std::binary_function<const double&, const double&, double>
00500     #endif
00501     {
00502         result_type
00503         operator()(
00504             first_argument_type     theLHS,
00505             second_argument_type    theRHS) const
00506         {
00507             return multiply(theLHS, theRHS);
00508         }
00509     };
00510 
00511     #if defined(XALAN_NO_NAMESPACES)
00512     struct divideFunction : public binary_function<const double&, const double&, double>
00513     #else
00514     struct divideFunction : public std::binary_function<const double&, const double&, double>
00515     #endif
00516     {
00517         result_type
00518         operator()(
00519             first_argument_type     theLHS,
00520             second_argument_type    theRHS) const
00521         {
00522             return divide(theLHS, theRHS);
00523         }
00524     };
00525 
00526     #if defined(XALAN_NO_NAMESPACES)
00527     struct modulusFunction : public binary_function<const double&, const double&, double>
00528     #else
00529     struct modulusFunction : public std::binary_function<const double&, const double&, double>
00530     #endif
00531     {
00532         result_type
00533         operator()(
00534             first_argument_type     theLHS,
00535             second_argument_type    theRHS) const
00536         {
00537             return modulus(theLHS, theRHS);
00538         }
00539     };
00540 
00541     #if defined(XALAN_NO_NAMESPACES)
00542     struct negativeFunction : public unary_function<const double&, double>
00543     #else
00544     struct negativeFunction : public std::unary_function<const double&, double>
00545     #endif
00546     {
00547         result_type
00548         operator()(argument_type    theDouble) const
00549         {
00550             return negative(theDouble);
00551         }
00552     };
00553 
00561     static bool
00562     isValid(const XalanDOMString    theString);
00563 
00571     static bool
00572     isValid(const XalanDOMChar*     theString);
00573 
00582     static double
00583     toDouble(const XalanDOMString&  theString);
00584 
00593     static double
00594     toDouble(const XalanDOMChar*    theString);
00595 
00603     static double
00604     round(double    theValue);
00605 
00606     typedef const unsigned int*                     DWORDPointerType;
00607     typedef XALAN_UNALIGNED const unsigned int*     UnalignedDWORDPointerType;
00608 
00609 private:
00610 
00611     static const double         s_NaN;
00612     static const double         s_positiveInfinity;
00613     static const double         s_negativeInfinity;
00614     static const double         s_positiveZero;
00615     static const double         s_negativeZero;
00616 
00617     static const DWORDPointerType           s_NaNFirstDWORD;
00618     static const UnalignedDWORDPointerType  s_NaNSecondDWORD;
00619 
00620     static const DWORDPointerType           s_positiveZeroFirstDWORD;
00621     static const UnalignedDWORDPointerType  s_positiveZeroSecondDWORD;
00622 
00623     static const DWORDPointerType           s_negativeZeroFirstDWORD;
00624     static const UnalignedDWORDPointerType  s_negativeZeroSecondDWORD;
00625 };
00626 
00627 
00628 
00629 #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++ XSL Transformer Version 1.1
Copyright © 2000, 2001 The Apache Software Foundation. All Rights Reserved.