What uncommon floating-point sizes exist in C++ compilers?

后端 未结 3 505
谎友^
谎友^ 2021-01-14 17:59

The C++14 draft standard seems rather quiet about the specific requirements for float, double and long double, although these sizes seem to be common:

3条回答
  •  生来不讨喜
    2021-01-14 18:31

    "float" and "double" are de-facto standardised on the IEEE single and double precision representations. I would put assuming these sizes in the same category as assuming CHAR_BIT==8. Some older arm systems did have wierd "mixed-endian" doubles, but unless you are working with retro stuff you are unlikely to encounter that nowadays.

    long double on the other hand is far more variable. Sometimes it's IEEE double precision, sometimes it's 80 bit x87 extended, sometimes it's IEEE quad precision , sometimes it's a "double double" format made up from two IEEE double precision numbers added together.

    So in portable code you can't rely on "long double" being any better than "double".

提交回复
热议问题