0

After going through various posts concerning this topic, it seems that things like floating point division by zero behavior isn't universally agreed upon when is_iec559 is true, unlike an analogous situation in C, where there's Annex F which describes what floating point operations do. It's been many years since this was discussed, so I thought something might have changed, so I'm asking:

Assuming is_iec559 is true in an implementation, are there any implications about about the basic +-*/ operations when it comes to otherwise undefined behavior in the c++ standard, e.g. division by zero returning infinity? Or does is_iec559 only guarantee the data storage format? Does it even guarantee anything?

More practically, are there any actual major implementations where this is not the case (i.e. is_iec559 can be true, and yet +-*/ do not conform to the IEC559 standard) under certain optimization flags etc.?

Jake1234
  • 187
  • 1
  • 7
  • Division by zero behavior is universally agreed upon when `is_iec559` is true. That universal agreement is called a *standard*. I'm not sure what happens to the `is_iec559` check when the compiler is given flags that disable some-or-all of guaranteed behaviors. I believe the switches involved caution that the flags should not be used if those behaviors should be in effect. (e.g., if the doubles will **never** be NaN, disabling NaN behaviors is okay... until a NaN slips in, in which case we're not in Kansas anymore). – Eljay Jun 25 '23 at 14:30
  • @Eljay It seems to be at least slightly contradictory to me that the standard describes something like division by zero to be UB conditionally for a float, and yet if `is_iec559` is true, float should conform to IEC559. Relevant discussion can be found at https://stackoverflow.com/questions/42926763/the-behaviour-of-floating-point-division-by-zero – Jake1234 Jun 25 '23 at 15:06
  • Adrian Maire's answer to the question that you linked appears to answer your question. The standard takes a loosey-goosey stance on floating point numbers because there are platforms that are not IEC 559 compliant. The standard accommodates the needs of those non-IEC 559 platforms as well — which makes relying on portable floating point behavior tricky. – Eljay Jun 25 '23 at 15:10
  • @Eljay Alright, thanks. Just to confirm - if `is_iec559` is true, this concerns everything about the floating type? Data layout, comparison operations, and all the basic (`+-*/` )operations? E.g. division of `1.0f/+0.0f` is guaranteed to be +infinity? – Jake1234 Jun 25 '23 at 20:31
  • Also, here is another seemingly conflicting situation: https://stackoverflow.com/questions/56097944/are-floating-point-operations-resulting-in-infinity-undefined-behavior-for-iec-5 It's in a constexpr context, but it's somewhat conflicting regardless. – Jake1234 Jun 25 '23 at 21:11
  • For platforms that have IEC 559 hardware, the only non-compliance with any C++ that I am aware of is if the program opts-out of IEC 559 compliance (e.g., fast math flags). I presume that such programs will still programmatically claim `is_iec559` compliance. – Eljay Jun 25 '23 at 21:27

0 Answers0