Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Overview

The header <boost/cstdfloat.hpp> provides optional standardized floating-point typedefs having specified widths. These are useful for writing portable code because they should behave identically on all platforms. These typedefs are the floating-point analog of specified-width integers in <cstdint> and stdint.h.

The typedefs are based on N3626 proposed for a new C++14 standard header <cstdfloat> and N1703 proposed for a new C language standard header <stdfloat.h>.

All typedefs are in namespace boost (would be in namespace std if eventually standardized).

The typedefs include float16_t, float32_t, float64_t, float80_t, float128_t, their corresponding least and fast types, and the corresponding maximum-width type. The typedefs are based on underlying built-in types such as float, double, or long double, or the proposed N2016 short float type, or based on other compiler-specific non-standardized types such as __float128. The underlying types of these typedefs must conform with the corresponding specifications of binary16, binary32, binary64, and binary128 in IEEE_floating_point floating-point format, and std::numeric_limits<>::is_iec559 == true.

The 128-bit floating-point type (of great interest in scientific and numeric programming) is not required in the Boost header, and may not be supplied for all platforms/compilers, because compiler support for a 128-bit floating-point type is not mandated by either the C standard or the C++ standard.

If 128-bit floating-point is supported, then including boost/cstdfloat.hpp provides a native 128-bit type, and includes other headers in folder boost/math/cstdfloat that provide C++ quad support for C math functions in <cmath>, <limits>, <iostream>, <complex>, and the available floating-point types.

One can also, more robustly, include boost/multiprecision/float128.hpp and this provides a thin wrapper selecting the appropriate 128-bit native type from cstdfloat if available, or else a 128-bit multiprecision type.

See Jahnke-Emden-Lambda function example for an example using both a <cmath> function and a Boost.Math function to evaluate a moderately interesting function, the Jahnke-Emden-Lambda function and normal distribution as an example of a statistical distribution from Boost.Math.


PrevUpHomeNext