Xalan-C++ API Documentation

The Xalan-C++ XSL Transformer Version 1.0

Main Page   Namespace List   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 unsigned long* const  theFirstDWORD =
00096 #if defined(XALAN_OLD_STYLE_CASTS)
00097             (const unsigned long*)&theNumber;
00098 #else
00099             reinterpret_cast<const unsigned long*>(&theNumber);
00100 #endif
00101 
00102         const unsigned long* const  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 
00133     // These can be used to initialize values, but should not
00134     // be used to do equality comparisons, as == may fail on
00135     // some platforms.
00136     //
00137 
00143     static double
00144     getNaN()
00145     {
00146         return s_NaN;
00147     }
00148 
00154     static double
00155     getPositiveInfinity()
00156     {
00157         return s_positiveInfinity;
00158     }
00159 
00165     static double
00166     getNegativeInfinity()
00167     {
00168         return s_negativeInfinity;
00169     }
00170 
00179     static bool
00180     equal(
00181             double  theLHS,
00182             double  theRHS);
00183 
00192     static bool
00193     notEqual(
00194             double  theLHS,
00195             double  theRHS);
00196 
00205     static bool
00206     lessThan(
00207             double  theLHS,
00208             double  theRHS);
00209 
00218     static bool
00219     lessThanOrEqual(
00220             double  theLHS,
00221             double  theRHS);
00222 
00231     static bool
00232     greaterThan(
00233             double  theLHS,
00234             double  theRHS);
00235 
00244     static bool
00245     greaterThanOrEqual(
00246             double  theLHS,
00247             double  theRHS);
00248 
00257     static double
00258     add(
00259             double  theLHS,
00260             double  theRHS);
00261 
00270     static double
00271     subtract(
00272             double  theLHS,
00273             double  theRHS);
00274 
00283     static double
00284     multiply(
00285             double  theLHS,
00286             double  theRHS);
00287 
00296     static double
00297     divide(
00298             double  theLHS,
00299             double  theRHS);
00300 
00310     static double
00311     modulus(
00312             double  theLHS,
00313             double  theRHS);
00314 
00323     static double
00324     negative(double theDouble);
00325 
00326     // Some functors to do the same thing.  This is for
00327     // STL integration...
00328     #if defined(XALAN_NO_NAMESPACES)
00329     struct equalFunction : public binary_function<const double&, const double&, bool>
00330     #else
00331     struct equalFunction : public std::binary_function<const double&, const double&, bool>
00332     #endif
00333     {
00334         result_type
00335         operator()(
00336             first_argument_type     theLHS,
00337             second_argument_type    theRHS) const
00338         {
00339             return equal(theLHS, theRHS);
00340         }
00341     };
00342 
00343     #if defined(XALAN_NO_NAMESPACES)
00344     struct notEqualFunction : public binary_function<const double&, const double&, bool>
00345     #else
00346     struct notEqualFunction : public std::binary_function<const double&, const double&, bool>
00347     #endif
00348     {
00349         result_type
00350         operator()(
00351             first_argument_type     theLHS,
00352             second_argument_type    theRHS) const
00353         {
00354             return notEqual(theLHS, theRHS);
00355         }
00356     };
00357 
00358     #if defined(XALAN_NO_NAMESPACES)
00359     struct lessThanFunction : public binary_function<const double&, const double&, bool>
00360     #else
00361     struct lessThanFunction : public std::binary_function<const double&, const double&, bool>
00362     #endif
00363     {
00364         result_type
00365         operator()(
00366             first_argument_type     theLHS,
00367             second_argument_type    theRHS) const
00368         {
00369             return lessThan(theLHS, theRHS);
00370         }
00371     };
00372 
00373     #if defined(XALAN_NO_NAMESPACES)
00374     struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00375     #else
00376     struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00377     #endif
00378     {
00379         result_type
00380         operator()(
00381             first_argument_type     theLHS,
00382             second_argument_type    theRHS) const
00383         {
00384             return lessThanOrEqual(theLHS, theRHS);
00385         }
00386     };
00387 
00388     #if defined(XALAN_NO_NAMESPACES)
00389     struct greaterThanFunction : public binary_function<const double&, const double&, bool>
00390     #else
00391     struct greaterThanFunction : public std::binary_function<const double&, const double&, bool>
00392     #endif
00393     {
00394         result_type
00395         operator()(
00396             first_argument_type     theLHS,
00397             second_argument_type    theRHS) const
00398         {
00399             return greaterThan(theLHS, theRHS);
00400         }
00401     };
00402 
00403     #if defined(XALAN_NO_NAMESPACES)
00404     struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool>
00405     #else
00406     struct greaterThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
00407     #endif
00408     {
00409         result_type
00410         operator()(
00411             first_argument_type     theLHS,
00412             second_argument_type    theRHS) const
00413         {
00414             return greaterThanOrEqual(theLHS, theRHS);
00415         }
00416     };
00417 
00418     #if defined(XALAN_NO_NAMESPACES)
00419     struct addFunction : public binary_function<const double&, const double&, double>
00420     #else
00421     struct addFunction : public std::binary_function<const double&, const double&, double>
00422     #endif
00423     {
00424         result_type
00425         operator()(
00426             first_argument_type     theLHS,
00427             second_argument_type    theRHS) const
00428         {
00429             return add(theLHS, theRHS);
00430         }
00431     };
00432 
00433     #if defined(XALAN_NO_NAMESPACES)
00434     struct subtractFunction : public binary_function<const double&, const double&, double>
00435     #else
00436     struct subtractFunction : public std::binary_function<const double&, const double&, double>
00437     #endif
00438     {
00439         result_type
00440         operator()(
00441             first_argument_type     theLHS,
00442             second_argument_type    theRHS) const
00443         {
00444             return subtract(theLHS, theRHS);
00445         }
00446     };
00447 
00448     #if defined(XALAN_NO_NAMESPACES)
00449     struct multiplyFunction : public binary_function<const double&, const double&, double>
00450     #else
00451     struct multiplyFunction : public std::binary_function<const double&, const double&, double>
00452     #endif
00453     {
00454         result_type
00455         operator()(
00456             first_argument_type     theLHS,
00457             second_argument_type    theRHS) const
00458         {
00459             return multiply(theLHS, theRHS);
00460         }
00461     };
00462 
00463     #if defined(XALAN_NO_NAMESPACES)
00464     struct divideFunction : public binary_function<const double&, const double&, double>
00465     #else
00466     struct divideFunction : public std::binary_function<const double&, const double&, double>
00467     #endif
00468     {
00469         result_type
00470         operator()(
00471             first_argument_type     theLHS,
00472             second_argument_type    theRHS) const
00473         {
00474             return divide(theLHS, theRHS);
00475         }
00476     };
00477 
00478     #if defined(XALAN_NO_NAMESPACES)
00479     struct modulusFunction : public binary_function<const double&, const double&, double>
00480     #else
00481     struct modulusFunction : public std::binary_function<const double&, const double&, double>
00482     #endif
00483     {
00484         result_type
00485         operator()(
00486             first_argument_type     theLHS,
00487             second_argument_type    theRHS) const
00488         {
00489             return modulus(theLHS, theRHS);
00490         }
00491     };
00492 
00493     #if defined(XALAN_NO_NAMESPACES)
00494     struct negativeFunction : public unary_function<const double&, double>
00495     #else
00496     struct negativeFunction : public std::unary_function<const double&, double>
00497     #endif
00498     {
00499         result_type
00500         operator()(argument_type    theDouble) const
00501         {
00502             return negative(theDouble);
00503         }
00504     };
00505 
00506     static double
00507     toDouble(const XalanDOMString&  theString);
00508 
00509     static double
00510     toDouble(const XalanDOMChar*    theString);
00511 
00512 private:
00513 
00514     static const double             s_NaN;
00515     static const double             s_positiveInfinity;
00516     static const double             s_negativeInfinity;
00517 
00518     static const unsigned long*     s_NaNFirstDWORD;
00519     static const unsigned long*     s_NaNSecondDWORD;
00520 };
00521 
00522 
00523 
00524 #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.0
Copyright © 2000 The Apache Software Foundation. All Rights Reserved.