We have two embedded projects: One of them is using the cosmic compiler and the other one is using GCC. Both abide by ISO/IEC 9899:1990.
When we initialize a float with the literal 14.8f
, it gets translated to the binary representation of 0x416CCCCC
on the cosmic compiler and 0x416CCCCD
by GCC.
The IEC standard at chapter 6.3.1.4, item 2, Floating types states:
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.
as we are using these numbers as threshold, this obviously makes a difference.
The cosmic compiler states that it uses a round down implementation.
As GCC is quite more complex I was wondering if it has a compiler flag that allows choosing of the behavior at compile time. So far I have only found that you can choose FE_DOWNWARD
, but that is related to run-time rather than compile-time.
Does anyone have a clue of such a flag for compile-time conversion?