Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

DoubleSupport.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(DOUBLESUPPORT_HEADER_GUARD_1357924680)
17 #define DOUBLESUPPORT_HEADER_GUARD_1357924680
18 
19 
20 
21 // Base include file. Must be first.
23 
24 
25 
26 #include <cmath>
27 #include <functional>
28 
29 
30 
32 
33 
34 
35 XALAN_CPP_NAMESPACE_BEGIN
36 
37 
38 
39 XALAN_USING_XERCES(MemoryManager)
40 
41 
42 
43 // A class to help us support IEEE 754.
45 {
46 public:
47 
52  static void
53  initialize();
54 
58  static void
59  terminate();
60 
61 
62  // Use these functions to determine if a value represents one of these
63  // specia values. On some platforms, regular C/C++ operators don't work
64  // as we need them too, so we have these helper functions.
65 
72  static bool
73  isNaN(double theNumber)
74  {
75  return s_NaN == theNumber;
76  }
77 
84  static bool
85  isPositiveInfinity(double theNumber)
86  {
87  return s_positiveInfinity == theNumber;
88  }
89 
96  static bool
97  isNegativeInfinity(double theNumber)
98  {
99  return s_negativeInfinity == theNumber;
100  }
101 
108  static bool
109  isPositiveZero(double theNumber)
110  {
111  return s_positiveZero == theNumber;
112  }
113 
120  static bool
121  isNegativeZero(double theNumber)
122  {
123  return s_negativeZero == theNumber;
124  }
125 
126  // These can be used to initialize values, but should not
127  // be used to do equality comparisons, as == may fail on
128  // some platforms.
129  //
130 
136  static double
138  {
139  return s_NaN.d;
140  }
141 
147  static double
149  {
150  return s_positiveInfinity.d;
151  }
152 
158  static double
160  {
161  return s_negativeInfinity.d;
162  }
163 
172  static bool
173  equal(
174  double theLHS,
175  double theRHS);
176 
185  static bool
187  double theLHS,
188  double theRHS)
189  {
190  return !equal(theLHS, theRHS);
191  }
192 
201  static bool
202  lessThan(
203  double theLHS,
204  double theRHS);
205 
214  static bool
215  lessThanOrEqual(
216  double theLHS,
217  double theRHS);
218 
227  static bool
228  greaterThan(
229  double theLHS,
230  double theRHS);
231 
240  static bool
241  greaterThanOrEqual(
242  double theLHS,
243  double theRHS);
244 
253  static double
254  add(
255  double theLHS,
256  double theRHS);
257 
266  static double
267  subtract(
268  double theLHS,
269  double theRHS);
270 
279  static double
280  multiply(
281  double theLHS,
282  double theRHS);
283 
292  static double
293  divide(
294  double theLHS,
295  double theRHS);
296 
306  static double
307  modulus(
308  double theLHS,
309  double theRHS);
310 
319  static double
320  negative(double theDouble);
321 
329  static double
330  abs(double theDouble);
331 
332  // Some functors to do the same thing. This is for
333  // STL integration...
334  #if defined(XALAN_NO_STD_NAMESPACE)
335  struct equalFunction : public binary_function<const double&, const double&, bool>
336  #else
337  struct equalFunction : public std::binary_function<const double&, const double&, bool>
338  #endif
339  {
340  result_type
342  first_argument_type theLHS,
343  second_argument_type theRHS) const
344  {
345  return equal(theLHS, theRHS);
346  }
347  };
348 
349  #if defined(XALAN_NO_STD_NAMESPACE)
350  struct notEqualFunction : public binary_function<const double&, const double&, bool>
351  #else
352  struct notEqualFunction : public std::binary_function<const double&, const double&, bool>
353  #endif
354  {
355  result_type
357  first_argument_type theLHS,
358  second_argument_type theRHS) const
359  {
360  return notEqual(theLHS, theRHS);
361  }
362  };
363 
364  #if defined(XALAN_NO_STD_NAMESPACE)
365  struct lessThanFunction : public binary_function<const double&, const double&, bool>
366  #else
367  struct lessThanFunction : public std::binary_function<const double&, const double&, bool>
368  #endif
369  {
370  result_type
372  first_argument_type theLHS,
373  second_argument_type theRHS) const
374  {
375  return lessThan(theLHS, theRHS);
376  }
377  };
378 
379  #if defined(XALAN_NO_STD_NAMESPACE)
380  struct lessThanOrEqualFunction : public binary_function<const double&, const double&, bool>
381  #else
382  struct lessThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
383  #endif
384  {
385  result_type
387  first_argument_type theLHS,
388  second_argument_type theRHS) const
389  {
390  return lessThanOrEqual(theLHS, theRHS);
391  }
392  };
393 
394  #if defined(XALAN_NO_STD_NAMESPACE)
395  struct greaterThanFunction : public binary_function<const double&, const double&, bool>
396  #else
397  struct greaterThanFunction : public std::binary_function<const double&, const double&, bool>
398  #endif
399  {
400  result_type
402  first_argument_type theLHS,
403  second_argument_type theRHS) const
404  {
405  return greaterThan(theLHS, theRHS);
406  }
407  };
408 
409  #if defined(XALAN_NO_STD_NAMESPACE)
410  struct greaterThanOrEqualFunction : public binary_function<const double&, const double&, bool>
411  #else
412  struct greaterThanOrEqualFunction : public std::binary_function<const double&, const double&, bool>
413  #endif
414  {
415  result_type
417  first_argument_type theLHS,
418  second_argument_type theRHS) const
419  {
420  return greaterThanOrEqual(theLHS, theRHS);
421  }
422  };
423 
424  #if defined(XALAN_NO_STD_NAMESPACE)
425  struct addFunction : public binary_function<const double&, const double&, double>
426  #else
427  struct addFunction : public std::binary_function<const double&, const double&, double>
428  #endif
429  {
430  result_type
432  first_argument_type theLHS,
433  second_argument_type theRHS) const
434  {
435  return add(theLHS, theRHS);
436  }
437  };
438 
439  #if defined(XALAN_NO_STD_NAMESPACE)
440  struct subtractFunction : public binary_function<const double&, const double&, double>
441  #else
442  struct subtractFunction : public std::binary_function<const double&, const double&, double>
443  #endif
444  {
445  result_type
447  first_argument_type theLHS,
448  second_argument_type theRHS) const
449  {
450  return subtract(theLHS, theRHS);
451  }
452  };
453 
454  #if defined(XALAN_NO_STD_NAMESPACE)
455  struct multiplyFunction : public binary_function<const double&, const double&, double>
456  #else
457  struct multiplyFunction : public std::binary_function<const double&, const double&, double>
458  #endif
459  {
460  result_type
462  first_argument_type theLHS,
463  second_argument_type theRHS) const
464  {
465  return multiply(theLHS, theRHS);
466  }
467  };
468 
469  #if defined(XALAN_NO_STD_NAMESPACE)
470  struct divideFunction : public binary_function<const double&, const double&, double>
471  #else
472  struct divideFunction : public std::binary_function<const double&, const double&, double>
473  #endif
474  {
475  result_type
477  first_argument_type theLHS,
478  second_argument_type theRHS) const
479  {
480  return divide(theLHS, theRHS);
481  }
482  };
483 
484  #if defined(XALAN_NO_STD_NAMESPACE)
485  struct modulusFunction : public binary_function<const double&, const double&, double>
486  #else
487  struct modulusFunction : public std::binary_function<const double&, const double&, double>
488  #endif
489  {
490  result_type
492  first_argument_type theLHS,
493  second_argument_type theRHS) const
494  {
495  return modulus(theLHS, theRHS);
496  }
497  };
498 
499  #if defined(XALAN_NO_STD_NAMESPACE)
500  struct negativeFunction : public unary_function<const double&, double>
501  #else
502  struct negativeFunction : public std::unary_function<const double&, double>
503  #endif
504  {
505  result_type
506  operator()(argument_type theDouble) const
507  {
508  return negative(theDouble);
509  }
510  };
511 
519  static bool
520  isValid(const XalanDOMString& theString);
521 
529  static bool
530  isValid(const XalanDOMChar* theString);
531 
541  static double
542  toDouble(
543  const XalanDOMString& theString,
544  MemoryManager& theManager);
545 
555  static double
556  toDouble(
557  const XalanDOMChar* theString,
558  MemoryManager& theManager);
559 
567  static double
568  round(double theValue);
569 
577  static double
578  ceiling(double theValue)
579  {
580 #if defined(XALAN_STRICT_ANSI_HEADERS)
581  return std::ceil(theValue);
582 #else
583  return ceil(theValue);
584 #endif
585  }
586 
594  static double
595  floor(double theValue)
596  {
597 #if defined(XALAN_STRICT_ANSI_HEADERS)
598  return std::floor(theValue);
599 #else
600  return ::floor(theValue);
601 #endif
602  }
603 
604  typedef union
605  {
606  double d;
607  struct
608  {
609  unsigned int dw1;
610  unsigned int dw2;
611  } dwords;
612 
613  bool
614  operator==(double theNumber) const
615  {
616  const NumberUnion temp = { theNumber };
617 
618  return dwords.dw1 == temp.dwords.dw1 &&
619  dwords.dw2 == temp.dwords.dw2;
620  }
621 
622  } NumberUnion;
623 
624 private:
625 
626 #if defined(XALAN_NO_STD_NUMERIC_LIMITS)
627  static NumberUnion s_NaN;
628 #else
629  static const NumberUnion s_NaN;
630 #endif
631 
632  static const NumberUnion s_positiveInfinity;
633  static const NumberUnion s_negativeInfinity;
634  static const NumberUnion s_positiveZero;
635  static const NumberUnion s_negativeZero;
636 };
637 
638 
639 
640 XALAN_CPP_NAMESPACE_END
641 
642 
643 
644 #endif // DOUBLESUPPORT_HEADER_GUARD_1357924680

Interpreting class diagrams

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

dot

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

Apache Logo