How to check that IEEE 754 single-precision (32-bit) floating-point representation is used?

后端 未结 3 1753
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 06:20

I want to test the following things on my target board:

  • Is \'float\' implemented with IEEE 754 single-precision (32-bit) floating-point variable?
3条回答
  •  一整个雨季
    2020-12-18 07:00

    First of all, you can find the details about the ISO/IEC/IEEE 60559 (or IEEE 754) in Wikipedia:

    Floating point standard types

    As F. Goncalvez has told you, the macro __STDC_IEC_559__ brings you information about your compiler, if it conform IEEE 754 or not.

    In what follows, we

    However, you can obtain additional information with the macro FLT_EVAL_METHOD.

    The value of this macro means:

    • 0 All operations and constants are evaluated in the range and precision of the type used.

    • 1 The operations of types float and double are evaluated in the range and precision of double, and long double goes in your own way...

    • 2 The evaluations of all types are done in the precision and range of long double.

    • -1 Indeterminate

    • Other negative values: Implementation defined (it depends on your compiler).

    For example, if FLT_EVAL_METHOD == 2, and you hold the result of several calculations in a floating point variable x, then all operations and constants are calculated or processed in the best precition, that is, long double, but only the final result is rounded to the type that x has.

    This behaviour reduces the immpact of numerical errors.

    In order to know details about the floating point types, you have to watch the constant macros provided by the standard header .
    For example, see this link:

    Çharacteristics of floating point types


    In the sad case that your implementation does not conform to the IEEE 754 standard, you can try looking for details in the standard header , if it exists.
    Also, you have to read the documentation of your compiler.

    For example, the compiler GCC explains what does with floating point:

    Stadus of C99 features in GCC

提交回复
热议问题