Do compilers always round floating-point literals using roundTiesToEven?

1 week ago 5
ARTICLE AD BOX

I have the following assertions, which pass on GCC, Clang, and MSVC for an x86_64 target:

// round to nearest static_assert(0.1f == 0.100000001490116119385f); // ties to even static_assert(1.000000059604644775390625f == 1.f); // flush tiny values to zero static_assert(1e-1000f == 0);

Evidently, all major compilers use the roundTiesToEven rounding mode as specified in ISO/IEC 60559 or IEEE-754. However, such rounding isn't guaranteed by the standard; [lex.fcon] paragraph 3 states that the value of a floating-point-literal is "the larger or smaller representable value nearest the scaled value, chosen in an implementation-defined manner". None of these assertions are required to pass.

Are there any compilers or compiler targets where rounding is not done using roundTiesToEven? I suspect that this rounding mode is universally used, even if not guaranteed by the standard.


For reference, roundTiesToEven works as follows, according to ISO/IEC 60559:

the floating-point number nearest to the infinitely precise result shall be delivered; if the two nearest floating-point numbers bracketing an unrepresentable infinitely precise result are equally near, the one with an even least significant digit shall be delivered; if that is not possible, the one larger in magnitude shall be delivered

Read Entire Article