[issue31373] demoting floating float values to unrepresentable types is undefined behavior

Benjamin Peterson report at bugs.python.org
Sun Sep 10 16:57:02 EDT 2017


Benjamin Peterson added the comment:

I'm going to undo the changes to getargs.c and floatobject.c. I think the pytime.c change is still correct because the doubles are explicitly rounded before conversion (and the old code checked for error > 1.0).

It's hard to win here I think. The clang undefined behavior sanitizer uses FLT_MAX to make its determination:
runtime error: value 3.40282e+38 is outside the range of representable values of type 'float'

So to satisfy it and preserve the old behavior, we would presumably have to implement the rounding ourselves, which doesn't seem like fun.

Annex F of C99, which defines the requirements for C implementations using IEE754, says, "the conversions for floating types provide  the IEC 60559 conversions between floating-point precisions.". Those are, of course, fully defined. It seems like the undefined behavior sanitizer is being overzealous when the target supports IEEE754.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31373>
_______________________________________


More information about the Python-bugs-list mailing list