Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.8

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 00044 // Use these functions to determine if a value represents one of these 00045 // values. It seems that under some architectures, NaN will compare 00046 // as equal to any number, which is a big problem. Hence these helper 00047 // functions. 00048 00055 static bool 00056 isNaN(double theNumber) 00057 { 00058 const NumberUnion temp = { theNumber }; 00059 00060 return s_NaN.dwords.dw1 == temp.dwords.dw1 && 00061 s_NaN.dwords.dw2 == temp.dwords.dw2; 00062 } 00063 00070 static bool 00071 isPositiveInfinity(double theNumber) 00072 { 00073 return !isNaN(theNumber) && theNumber == s_positiveInfinity; 00074 } 00075 00082 static bool 00083 isNegativeInfinity(double theNumber) 00084 { 00085 return !isNaN(theNumber) && theNumber == s_negativeInfinity; 00086 } 00087 00094 static bool 00095 isPositiveZero(double theNumber) 00096 { 00097 const NumberUnion temp = { theNumber }; 00098 00099 return s_positiveZero.dwords.dw1 == temp.dwords.dw1 && 00100 s_positiveZero.dwords.dw2 == temp.dwords.dw2; 00101 } 00102 00109 static bool 00110 isNegativeZero(double theNumber) 00111 { 00112 const NumberUnion temp = { theNumber }; 00113 00114 return s_negativeZero.dwords.dw1 == temp.dwords.dw1 && 00115 s_negativeZero.dwords.dw2 == temp.dwords.dw2; 00116 } 00117 00118 // These can be used to initialize values, but should not 00119 // be used to do equality comparisons, as == may fail on 00120 // some platforms. 00121 // 00122 00128 static double 00129 getNaN() 00130 { 00131 return s_NaN.d; 00132 } 00133 00139 static double 00140 getPositiveInfinity() 00141 { 00142 return s_positiveInfinity; 00143 } 00144 00150 static double 00151 getNegativeInfinity() 00152 { 00153 return s_negativeInfinity; 00154 } 00155 00164 static bool 00165 equal( 00166 double theLHS, 00167 double theRHS); 00168 00177 static bool 00178 notEqual( 00179 double theLHS, 00180 double theRHS) 00181 { 00182 return !equal(theLHS, theRHS); 00183 } 00184 00193 static bool 00194 lessThan( 00195 double theLHS, 00196 double theRHS); 00197 00206 static bool 00207 lessThanOrEqual( 00208 double theLHS, 00209 double theRHS); 00210 00219 static bool 00220 greaterThan( 00221 double theLHS, 00222 double theRHS); 00223 00232 static bool 00233 greaterThanOrEqual( 00234 double theLHS, 00235 double theRHS); 00236 00245 static double 00246 add( 00247 double theLHS, 00248 double theRHS); 00249 00258 static double 00259 subtract( 00260 double theLHS, 00261 double theRHS); 00262 00271 static double 00272 multiply( 00273 double theLHS, 00274 double theRHS); 00275 00284 static double 00285 divide( 00286 double theLHS, 00287 double theRHS); 00288 00298 static double 00299 modulus( 00300 double theLHS, 00301 double theRHS); 00302 00311 static double 00312 negative(double theDouble); 00313 00314 // Some functors to do the same thing. This is for 00315 // STL integration... 00316 #if defined(XALAN_NO_STD_NAMESPACE) 00317 struct equalFunction : public binary_function<const double&, const double&, bool> 00318 #else 00319 struct equalFunction : public std::binary_function<const double&, const double&, bool> 00320 #endif 00321 { 00322 result_type 00323 operator()( 00324 first_argument_type theLHS, 00325 second_argument_type theRHS) const 00326 { 00327 return equal(theLHS, theRHS); 00328 } 00329 }; 00330 00331 #if defined(XALAN_NO_STD_NAMESPACE) 00332 struct notEqualFunction : public binary_function<const double&, const double&, bool> 00333 #else 00334 struct notEqualFunction : public std::binary_function<const double&, const double&, bool> 00335 #endif 00336 { 00337 result_type 00338 operator()( 00339 first_argument_type theLHS, 00340 second_argument_type theRHS) const 00341 { 00342 return notEqual(theLHS, theRHS); 00343 } 00344 }; 00345 00346 #if defined(XALAN_NO_STD_NAMESPACE) 00347 struct lessThanFunction : public binary_function<const double&, const double&, bool> 00348 #else 00349 struct lessThanFunction : public std::binary_function<const double&, const double&, bool> 00350 #endif 00351 { 00352 result_type 00353 operator()( 00354 first_argument_type theLHS, 00355 second_argument_type theRHS) const 00356 { 00357 return lessThan(theLHS, theRHS); 00358 } 00359 }; 00360 00361 #if defined(XALAN_NO_STD_NAMESPACE) 00362 struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool> 00363 #else 00364 struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool> 00365 #endif 00366 { 00367 result_type 00368 operator()( 00369 first_argument_type theLHS, 00370 second_argument_type theRHS) const 00371 { 00372 return lessThanOrEqual(theLHS, theRHS); 00373 } 00374 }; 00375 00376 #if defined(XALAN_NO_STD_NAMESPACE) 00377 struct greaterThanFunction : public binary_function<const double&, const double&, bool> 00378 #else 00379 struct greaterThanFunction : 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 greaterThan(theLHS, theRHS); 00388 } 00389 }; 00390 00391 #if defined(XALAN_NO_STD_NAMESPACE) 00392 struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool> 00393 #else 00394 struct greaterThanOrEqualFunction : 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 greaterThanOrEqual(theLHS, theRHS); 00403 } 00404 }; 00405 00406 #if defined(XALAN_NO_STD_NAMESPACE) 00407 struct addFunction : public binary_function<const double&, const double&, double> 00408 #else 00409 struct addFunction : public std::binary_function<const double&, const double&, double> 00410 #endif 00411 { 00412 result_type 00413 operator()( 00414 first_argument_type theLHS, 00415 second_argument_type theRHS) const 00416 { 00417 return add(theLHS, theRHS); 00418 } 00419 }; 00420 00421 #if defined(XALAN_NO_STD_NAMESPACE) 00422 struct subtractFunction : public binary_function<const double&, const double&, double> 00423 #else 00424 struct subtractFunction : public std::binary_function<const double&, const double&, double> 00425 #endif 00426 { 00427 result_type 00428 operator()( 00429 first_argument_type theLHS, 00430 second_argument_type theRHS) const 00431 { 00432 return subtract(theLHS, theRHS); 00433 } 00434 }; 00435 00436 #if defined(XALAN_NO_STD_NAMESPACE) 00437 struct multiplyFunction : public binary_function<const double&, const double&, double> 00438 #else 00439 struct multiplyFunction : public std::binary_function<const double&, const double&, double> 00440 #endif 00441 { 00442 result_type 00443 operator()( 00444 first_argument_type theLHS, 00445 second_argument_type theRHS) const 00446 { 00447 return multiply(theLHS, theRHS); 00448 } 00449 }; 00450 00451 #if defined(XALAN_NO_STD_NAMESPACE) 00452 struct divideFunction : public binary_function<const double&, const double&, double> 00453 #else 00454 struct divideFunction : public std::binary_function<const double&, const double&, double> 00455 #endif 00456 { 00457 result_type 00458 operator()( 00459 first_argument_type theLHS, 00460 second_argument_type theRHS) const 00461 { 00462 return divide(theLHS, theRHS); 00463 } 00464 }; 00465 00466 #if defined(XALAN_NO_STD_NAMESPACE) 00467 struct modulusFunction : public binary_function<const double&, const double&, double> 00468 #else 00469 struct modulusFunction : 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 modulus(theLHS, theRHS); 00478 } 00479 }; 00480 00481 #if defined(XALAN_NO_STD_NAMESPACE) 00482 struct negativeFunction : public unary_function<const double&, double> 00483 #else 00484 struct negativeFunction : public std::unary_function<const double&, double> 00485 #endif 00486 { 00487 result_type 00488 operator()(argument_type theDouble) const 00489 { 00490 return negative(theDouble); 00491 } 00492 }; 00493 00501 static bool 00502 isValid(const XalanDOMString& theString); 00503 00511 static bool 00512 isValid(const XalanDOMChar* theString); 00513 00522 static double 00523 toDouble(const XalanDOMString& theString); 00524 00533 static double 00534 toDouble(const XalanDOMChar* theString); 00535 00543 static double 00544 round(double theValue); 00545 00553 static double 00554 ceiling(double theValue) 00555 { 00556 #if defined(XALAN_STRICT_ANSI_HEADERS) 00557 return std::ceil(theValue); 00558 #else 00559 return ceil(theValue); 00560 #endif 00561 } 00562 00570 static double 00571 floor(double theValue) 00572 { 00573 #if defined(XALAN_STRICT_ANSI_HEADERS) 00574 return std::floor(theValue); 00575 #else 00576 return ::floor(theValue); 00577 #endif 00578 } 00579 00580 typedef union 00581 { 00582 double d; 00583 struct 00584 { 00585 unsigned int dw1; 00586 unsigned int dw2; 00587 } dwords; 00588 } NumberUnion; 00589 00590 private: 00591 00592 static const NumberUnion s_NaN; 00593 static const double s_positiveInfinity; 00594 static const double s_negativeInfinity; 00595 static const NumberUnion s_positiveZero; 00596 static const NumberUnion s_negativeZero; 00597 }; 00598 00599 00600 00601 XALAN_CPP_NAMESPACE_END 00602 00603 00604 00605 #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.8
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.