fpclassify.qbk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [section:fpclass Floating-Point Classification: Infinities and NaNs]
  2. [h4 Synopsis]
  3. #define FP_ZERO /* implementation specific value */
  4. #define FP_NORMAL /* implementation specific value */
  5. #define FP_INFINITE /* implementation specific value */
  6. #define FP_NAN /* implementation specific value */
  7. #define FP_SUBNORMAL /* implementation specific value */
  8. template <class T>
  9. int fpclassify(T t);
  10. template <class T>
  11. bool isfinite(T z); // Neither infinity nor NaN.
  12. template <class T>
  13. bool isinf(T t); // Infinity (+ or -).
  14. template <class T>
  15. bool isnan(T t); // NaN.
  16. template <class T>
  17. bool isnormal(T t); // isfinite and not denormalised.
  18. #include <boost\math\special_functions\fpclassify.hpp>
  19. to use these functions.
  20. [h4 Description]
  21. These functions provide the same functionality as the macros with the same
  22. name in C99, indeed if the C99 macros are available, then these functions
  23. are implemented in terms of them, otherwise they rely on `std::numeric_limits<>`
  24. to function.
  25. Note that the definition of these functions
  26. ['does not suppress the definition of these names as macros by math.h]
  27. on those platforms that already provide
  28. these as macros. That mean that the following have differing meanings:
  29. using namespace boost::math;
  30. // This might call a global macro if defined,
  31. // but might not work if the type of z is unsupported
  32. // by the std lib macro:
  33. isnan(z);
  34. //
  35. // This calls the Boost version
  36. // (found via the "using namespace boost::math" declaration)
  37. // it works for any type that has numeric_limits support for type z:
  38. (isnan)(z);
  39. //
  40. // As above but with explicit namespace qualification.
  41. (boost::math::isnan)(z);
  42. //
  43. // This will cause a compiler error if isnan is a native macro:
  44. boost::math::isnan(z);
  45. // So always use instead:
  46. (boost::math::isnan)(z);
  47. //
  48. // You can also add a using statement,
  49. // globally to a .cpp file, or to a local function in a .hpp file.
  50. using boost::math::isnan;
  51. // so you can write the shorter and less cluttered
  52. (isnan)(z)
  53. // But, as above, if isnan is a native macro, this causes a compiler error,
  54. // because the macro always 'gets' the name first, unless enclosed in () brackets.
  55. Detailed descriptions for each of these functions follows:
  56. template <class T>
  57. int fpclassify(T t);
  58. Returns an integer value that classifies the value /t/:
  59. [table
  60. [[fpclassify value] [class of t.]]
  61. [[FP_ZERO] [If /t/ is zero.]]
  62. [[FP_NORMAL] [If /t/ is a non-zero, non-denormalised finite value.]]
  63. [[FP_INFINITE] [If /t/ is plus or minus infinity.]]
  64. [[FP_NAN] [If /t/ is a NaN.]]
  65. [[FP_SUBNORMAL] [If /t/ is a denormalised number.]]
  66. ]
  67. template <class T>
  68. bool isfinite(T z);
  69. Returns true only if /z/ is not an infinity or a NaN.
  70. template <class T>
  71. bool isinf(T t);
  72. Returns true only if /z/ is plus or minus infinity.
  73. template <class T>
  74. bool isnan(T t);
  75. Returns true only if /z/ is a [@http://en.wikipedia.org/wiki/NaN NaN].
  76. template <class T>
  77. bool isnormal(T t);
  78. Returns true only if /z/ is a normal number (not zero, infinite, NaN, or denormalised).
  79. [h5 Floating-point format]
  80. If you wish to find details of the floating-point format for any particular processor,
  81. there is a program
  82. [@../../example/inspect_fp.cpp inspect_fp.cpp]
  83. by Johan Rade which can be used to print out the processor type,
  84. endianness, and detailed bit layout of a selection of floating-point values,
  85. including infinity and NaNs.
  86. [endsect] [/section:fpclass Floating Point Classification: Infinities and NaNs]
  87. [/
  88. Copyright 2006, 2008, 2011 John Maddock, Johan Rade and Paul A. Bristow.
  89. Distributed under the Boost Software License, Version 1.0.
  90. (See accompanying file LICENSE_1_0.txt or copy at
  91. http://www.boost.org/LICENSE_1_0.txt).
  92. ]