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