How do I use decimal (float) in C++?

前端 未结 5 1680
广开言路
广开言路 2021-02-10 00:56

According to IEEE 754-2008 there are

There are three binary floating-point basic formats (which can be encoded using 32, 64 or 128 bits) and two decimal f

5条回答
  •  猫巷女王i
    2021-02-10 01:23

    C++ does not specify that floats must be 32-bit or that doubles must be 64-bit. It does not even require there to be 8 bits in a byte (though there do have to be at least 8).

    [C++11: 3.9.1/8]: There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

    See the documentation for your toolchain and platform to see what its type sizes are. It might support long double, which in turn might be what you want.

提交回复
热议问题