Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Rationale

The implementation of <boost/cstdfloat.hpp> is designed to utilize <float.h>, defined in the 1989 C standard. The preprocessor is used to query certain preprocessor definitions in <float.h> such as FLT_MAX, DBL_MAX, etc. Based on the results of these queries, an attempt is made to automatically detect the presence of built-in floating-point types having specified widths. An unequivocal test regarding conformance with IEEE_floating_point (IEC599) based on std::numeric_limits<>::is_iec559 is performed with BOOST_STATIC_ASSERT.

In addition, this Boost implementation <boost/cstdfloat.hpp> supports an 80-bit floating-point typedef if it can be detected, and a 128-bit floating-point typedef if it can be detected, provided that the underlying types conform with IEEE-754 precision extension (ifstd::numeric_limits<>::is_iec559 is true for this type).

The header <boost/cstdfloat.hpp> makes the standardized floating-point typedefs safely available in namespace boost without placing any names in namespace std. The intention is to complement rather than compete with a potential future C/C++ Standard Library that may contain these typedefs. Should some future C/C++ standard include <stdfloat.h> and <cstdfloat>, then <boost/cstdfloat.hpp> will continue to function, but will become redundant and may be safely deprecated.

Because <boost/cstdfloat.hpp> is a Boost header, its name conforms to the boost header naming conventions, not the C++ Standard Library header naming conventions.

[Note] Note

<boost/cstdfloat.hpp> cannot synthesize or create a typedef if the underlying type is not provided by the compiler. For example, if a compiler does not have an underlying floating-point type with 128 bits (highly sought-after in scientific and numeric programming), then float128_t and its corresponding least and fast types are not provided by <boost/cstdfloat.hpp>.

[Warning] Warning

If <boost/cstdfloat.hpp> uses a compiler-specific non-standardized type (not derived from float, double, or long double) for one or more of its floating-point typedefs, then there is no guarantee that specializations of numeric_limits<> will be available for these types. Specializations of numeric_limits<> will only be available for these types if the compiler itself supports corresponding specializations for the underlying type(s).

[Warning] Warning

As an implementation artifact, certain C macro names from <float.h> may possibly be visible to users of <boost/cstdfloat.hpp>. Don't rely on using these macros; they are not part of any Boost-specified interface. Use std::numeric_limits<> for floating-point ranges, etc. instead.

[Tip] Tip

For best results, <boost/cstdfloat.hpp> should be #included before other headers like <cmath>.

In addition to detecting and type defining built-in types such as float, double, and long double, <boost/castfloat.hpp> may also detect compiler-specific floating-point type(s) and subsequently type define these to floating-point types having specified widths in namespace boost. When this occurs, and <boost/castfloat.hpp> type defines such a non-built-in type to one of boost::float16_t, boost::float32_t, boost::float80_t, or boost::float128_t, it might lead to ambiguous symbols for certain <cmath> functions in namespace std. See implementation for more details.

For this reason, making #include <boost/cstdfloat.hpp> the first include is usually best.


PrevUpHomeNext