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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Greatest-width floating-point typedef

The typedef floatmax_t designates a floating-point type capable of representing any value of any floating-point type in a given platform most precisely.

The greatest-width typedef is provided for all platforms, but, of course, the size may vary.

To provide floating-point constants most precisely representable for a floatmax_t type, use the macro BOOST_FLOATMAX_C.

For example, replace a constant 123.4567890123456789012345678901234567890 with


If, for example, floatmax_t is float64_t then the result will be equivalent to a long double suffixed with L, but if floatmax_t is float128_t then the result will be equivalent to a quad type suffixed with Q (assuming, of course, that float128_t (__float128 or Quad) is supported).

If we display with max_digits10, the maximum possibly significant decimal digits:

#ifdef BOOST_FLOAT32_C
  std::cout.precision(boost::max_digits10<boost::float32_t>()); // Show all significant decimal digits,
  std::cout.setf(std::ios::showpoint); // including all significant trailing zeros.
  std::cout << "BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = "
    << BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) << std::endl;
  //   BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787

then on a 128-bit platform (GCC 4.8.1 or higher with quadmath):

BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787
BOOST_FLOAT64_C(123.4567890123456789012345678901234567890) = 123.45678901234568
BOOST_FLOAT80_C(123.4567890123456789012345678901234567890) = 123.456789012345678903
BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.456789012345678901234567890123453