Search code examples
c++cboostfloating-point

Fixed-size floating point types


In the stdint.h (C99), boost/cstdint.hpp, and cstdint (C++0x) headers there is, among others, the type int32_t.

Are there similar fixed-size floating point types? Something like float32_t?


Solution

  • IEEE 754-compliant fixed-precision floating point numbers were introduced in C++23.

    Here's how to instantiate a 64-bit float:

    #include <stdfloat>
    int main()
    {
        std::float64_t f = 0.1f64;
    }
    

    The implementation proposal can be found here