00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999-2002 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 <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00064 00065 00066 00067 #include <cmath> 00068 #include <functional> 00069 00070 00071 00072 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00073 00074 00075 00076 XALAN_CPP_NAMESPACE_BEGIN 00077 00078 00079 00080 // A class to help us support IEEE 754. 00081 class XALAN_PLATFORMSUPPORT_EXPORT DoubleSupport 00082 { 00083 public: 00084 00085 // Use these functions to determine if a value represents one of these 00086 // values. It seems that under some architectures, NaN will compare 00087 // as equal to any number, which is a big problem. Hence these helper 00088 // functions. 00089 00096 static bool 00097 isNaN(double theNumber) 00098 { 00099 const NumberUnion temp = { theNumber }; 00100 00101 return s_NaN.dwords.dw1 == temp.dwords.dw1 && 00102 s_NaN.dwords.dw2 == temp.dwords.dw2; 00103 } 00104 00111 static bool 00112 isPositiveInfinity(double theNumber) 00113 { 00114 return !isNaN(theNumber) && theNumber == s_positiveInfinity; 00115 } 00116 00123 static bool 00124 isNegativeInfinity(double theNumber) 00125 { 00126 return !isNaN(theNumber) && theNumber == s_negativeInfinity; 00127 } 00128 00135 static bool 00136 isPositiveZero(double theNumber) 00137 { 00138 const NumberUnion temp = { theNumber }; 00139 00140 return s_positiveZero.dwords.dw1 == temp.dwords.dw1 && 00141 s_positiveZero.dwords.dw2 == temp.dwords.dw2; 00142 } 00143 00150 static bool 00151 isNegativeZero(double theNumber) 00152 { 00153 const NumberUnion temp = { theNumber }; 00154 00155 return s_negativeZero.dwords.dw1 == temp.dwords.dw1 && 00156 s_negativeZero.dwords.dw2 == temp.dwords.dw2; 00157 } 00158 00159 // These can be used to initialize values, but should not 00160 // be used to do equality comparisons, as == may fail on 00161 // some platforms. 00162 // 00163 00169 static double 00170 getNaN() 00171 { 00172 return s_NaN.d; 00173 } 00174 00180 static double 00181 getPositiveInfinity() 00182 { 00183 return s_positiveInfinity; 00184 } 00185 00191 static double 00192 getNegativeInfinity() 00193 { 00194 return s_negativeInfinity; 00195 } 00196 00205 static bool 00206 equal( 00207 double theLHS, 00208 double theRHS); 00209 00218 static bool 00219 notEqual( 00220 double theLHS, 00221 double theRHS) 00222 { 00223 return !equal(theLHS, theRHS); 00224 } 00225 00234 static bool 00235 lessThan( 00236 double theLHS, 00237 double theRHS); 00238 00247 static bool 00248 lessThanOrEqual( 00249 double theLHS, 00250 double theRHS); 00251 00260 static bool 00261 greaterThan( 00262 double theLHS, 00263 double theRHS); 00264 00273 static bool 00274 greaterThanOrEqual( 00275 double theLHS, 00276 double theRHS); 00277 00286 static double 00287 add( 00288 double theLHS, 00289 double theRHS); 00290 00299 static double 00300 subtract( 00301 double theLHS, 00302 double theRHS); 00303 00312 static double 00313 multiply( 00314 double theLHS, 00315 double theRHS); 00316 00325 static double 00326 divide( 00327 double theLHS, 00328 double theRHS); 00329 00339 static double 00340 modulus( 00341 double theLHS, 00342 double theRHS); 00343 00352 static double 00353 negative(double theDouble); 00354 00355 // Some functors to do the same thing. This is for 00356 // STL integration... 00357 #if defined(XALAN_NO_STD_NAMESPACE) 00358 struct equalFunction : public binary_function<const double&, const double&, bool> 00359 #else 00360 struct equalFunction : public std::binary_function<const double&, const double&, bool> 00361 #endif 00362 { 00363 result_type 00364 operator()( 00365 first_argument_type theLHS, 00366 second_argument_type theRHS) const 00367 { 00368 return equal(theLHS, theRHS); 00369 } 00370 }; 00371 00372 #if defined(XALAN_NO_STD_NAMESPACE) 00373 struct notEqualFunction : public binary_function<const double&, const double&, bool> 00374 #else 00375 struct notEqualFunction : public std::binary_function<const double&, const double&, bool> 00376 #endif 00377 { 00378 result_type 00379 operator()( 00380 first_argument_type theLHS, 00381 second_argument_type theRHS) const 00382 { 00383 return notEqual(theLHS, theRHS); 00384 } 00385 }; 00386 00387 #if defined(XALAN_NO_STD_NAMESPACE) 00388 struct lessThanFunction : public binary_function<const double&, const double&, bool> 00389 #else 00390 struct lessThanFunction : public std::binary_function<const double&, const double&, bool> 00391 #endif 00392 { 00393 result_type 00394 operator()( 00395 first_argument_type theLHS, 00396 second_argument_type theRHS) const 00397 { 00398 return lessThan(theLHS, theRHS); 00399 } 00400 }; 00401 00402 #if defined(XALAN_NO_STD_NAMESPACE) 00403 struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool> 00404 #else 00405 struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool> 00406 #endif 00407 { 00408 result_type 00409 operator()( 00410 first_argument_type theLHS, 00411 second_argument_type theRHS) const 00412 { 00413 return lessThanOrEqual(theLHS, theRHS); 00414 } 00415 }; 00416 00417 #if defined(XALAN_NO_STD_NAMESPACE) 00418 struct greaterThanFunction : public binary_function<const double&, const double&, bool> 00419 #else 00420 struct greaterThanFunction : public std::binary_function<const double&, const double&, bool> 00421 #endif 00422 { 00423 result_type 00424 operator()( 00425 first_argument_type theLHS, 00426 second_argument_type theRHS) const 00427 { 00428 return greaterThan(theLHS, theRHS); 00429 } 00430 }; 00431 00432 #if defined(XALAN_NO_STD_NAMESPACE) 00433 struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool> 00434 #else 00435 struct greaterThanOrEqualFunction : public std::binary_function<const double&, const double&, bool> 00436 #endif 00437 { 00438 result_type 00439 operator()( 00440 first_argument_type theLHS, 00441 second_argument_type theRHS) const 00442 { 00443 return greaterThanOrEqual(theLHS, theRHS); 00444 } 00445 }; 00446 00447 #if defined(XALAN_NO_STD_NAMESPACE) 00448 struct addFunction : public binary_function<const double&, const double&, double> 00449 #else 00450 struct addFunction : public std::binary_function<const double&, const double&, double> 00451 #endif 00452 { 00453 result_type 00454 operator()( 00455 first_argument_type theLHS, 00456 second_argument_type theRHS) const 00457 { 00458 return add(theLHS, theRHS); 00459 } 00460 }; 00461 00462 #if defined(XALAN_NO_STD_NAMESPACE) 00463 struct subtractFunction : public binary_function<const double&, const double&, double> 00464 #else 00465 struct subtractFunction : public std::binary_function<const double&, const double&, double> 00466 #endif 00467 { 00468 result_type 00469 operator()( 00470 first_argument_type theLHS, 00471 second_argument_type theRHS) const 00472 { 00473 return subtract(theLHS, theRHS); 00474 } 00475 }; 00476 00477 #if defined(XALAN_NO_STD_NAMESPACE) 00478 struct multiplyFunction : public binary_function<const double&, const double&, double> 00479 #else 00480 struct multiplyFunction : public std::binary_function<const double&, const double&, double> 00481 #endif 00482 { 00483 result_type 00484 operator()( 00485 first_argument_type theLHS, 00486 second_argument_type theRHS) const 00487 { 00488 return multiply(theLHS, theRHS); 00489 } 00490 }; 00491 00492 #if defined(XALAN_NO_STD_NAMESPACE) 00493 struct divideFunction : public binary_function<const double&, const double&, double> 00494 #else 00495 struct divideFunction : public std::binary_function<const double&, const double&, double> 00496 #endif 00497 { 00498 result_type 00499 operator()( 00500 first_argument_type theLHS, 00501 second_argument_type theRHS) const 00502 { 00503 return divide(theLHS, theRHS); 00504 } 00505 }; 00506 00507 #if defined(XALAN_NO_STD_NAMESPACE) 00508 struct modulusFunction : public binary_function<const double&, const double&, double> 00509 #else 00510 struct modulusFunction : public std::binary_function<const double&, const double&, double> 00511 #endif 00512 { 00513 result_type 00514 operator()( 00515 first_argument_type theLHS, 00516 second_argument_type theRHS) const 00517 { 00518 return modulus(theLHS, theRHS); 00519 } 00520 }; 00521 00522 #if defined(XALAN_NO_STD_NAMESPACE) 00523 struct negativeFunction : public unary_function<const double&, double> 00524 #else 00525 struct negativeFunction : public std::unary_function<const double&, double> 00526 #endif 00527 { 00528 result_type 00529 operator()(argument_type theDouble) const 00530 { 00531 return negative(theDouble); 00532 } 00533 }; 00534 00542 static bool 00543 isValid(const XalanDOMString& theString); 00544 00552 static bool 00553 isValid(const XalanDOMChar* theString); 00554 00563 static double 00564 toDouble(const XalanDOMString& theString); 00565 00574 static double 00575 toDouble(const XalanDOMChar* theString); 00576 00584 static double 00585 round(double theValue); 00586 00594 static double 00595 ceiling(double theValue) 00596 { 00597 #if defined(XALAN_STRICT_ANSI_HEADERS) 00598 return std::ceil(theValue); 00599 #else 00600 return ceil(theValue); 00601 #endif 00602 } 00603 00611 static double 00612 floor(double theValue) 00613 { 00614 #if defined(XALAN_STRICT_ANSI_HEADERS) 00615 return std::floor(theValue); 00616 #else 00617 return ::floor(theValue); 00618 #endif 00619 } 00620 00621 typedef union 00622 { 00623 double d; 00624 struct 00625 { 00626 unsigned int dw1; 00627 unsigned int dw2; 00628 } dwords; 00629 } NumberUnion; 00630 00631 private: 00632 00633 static const NumberUnion s_NaN; 00634 static const double s_positiveInfinity; 00635 static const double s_negativeInfinity; 00636 static const NumberUnion s_positiveZero; 00637 static const NumberUnion s_negativeZero; 00638 }; 00639 00640 00641 00642 XALAN_CPP_NAMESPACE_END 00643 00644 00645 00646 #endif // DOUBLESUPPORT_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.6 |
|