C floating translation

We have 2 built-in projects. One of them uses a space compiler, and the other uses GCC. Both adhere to ISO / IEC 9899: 1990.

When we initialize a float with the literal 14.8f, it translates to binary representation 0x416CCCCC on the space compiler and 0x416CCCCD on GCC.

IEC standard in chapter 6.2.1.4 Status of floating types:

If the value being converted is in the range of values that can be represented but
cannot be represented exactly, the result is either the nearest higher or nearest lower value, chosen in an implementation-defined manner.

since we use these numbers as thresholds, this obviously matters. The space compiler claims to use a rounded implementation. Since GCC is quite complex, I was wondering if it has a compiler flag that allows you to choose behavior at compile time. So far, I have found that you can select FE_DOWNWARD, but this is due to runtime, not compilation.

Does anyone have a key for this flag to convert compile time?

+4
source share
1 answer

For reference, the reference to the relevant chapter in the GCC manual reads:

As the nearest representable value or a larger or smaller representable value directly adjacent to the nearest representable value, some floating-point constants are selected (C90 6.1.3.1, C99 and C11 6.4.4.2).

C99 Applied F.

And in my draft C99 standard, Appendix F says:

F.7.2 Translation

During broadcasting, the default IEC 60559 modes are valid:

- .
- ( ) , .
- ( )

, ,

  • GCC .
  • .

float , ( ) , .

+2

Source: https://habr.com/ru/post/1694048/


All Articles