4 ms·
> There is nothing in the C standard which makes that invalid. C only permits¹ optimizations that do not change semantics, so changing the result of a floating
by kps 12y ago
> There is nothing in the C standard which makes that invalid.
C only permits¹ optimizations that do not change semantics, so changing the result of a floating point expression is invalid. Example 5 on p16 of C11² makes this explicit: “Rearrangement for floating-point expressions is often restricted because of limitations in
precision as well as range. The implementation cannot generally apply the mathematical associative rules
for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of
overflow and underflow. Likewise, implementations cannot generally replace decimal constants in order to
rearrange expressions.”
¹ Of course many compilers have options that invoke something other than standard-conforming C.
² C11 final draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
- aidenn0 12y agoThanks for that; I've purchased the C11 standard, but haven't gotten around to reading it yet since I'm not likely to write anything in C11 for a few years yet.