2

Are HAS_SUBNORM and __STDC_IEC_559__ dependent? For example:

  • If __STDC_IEC_559__ is 1, then HAS_SUBNORM is 1.
  • If HAS_SUBNORM is 0, then __STDC_IEC_559__ is not 1.
pmor
  • 5,392
  • 4
  • 17
  • 36
  • 3
    Section F of the C standard has several sentences beginning "When subnormal results are supported," (ref: F.10.7.1/2, F.10.7.2/2, F.10.7.3/2), which suggests they are independent. – Ian Abbott Jul 02 '21 at 10:46
  • Thanks! It means that `__STDC_IEC_559__ is 1` != `conformance to IEEE 754`. Confused. – pmor Jul 03 '21 at 16:16

1 Answers1

1

Are HAS_SUBNORM and __STDC_IEC_559__ dependent?

I'd suggest no.
__STDC_IEC_559__ == 1 and xxx_HAS_SUBNORM != 1 possible.

C17 Appendix F specifies what is needed to conform to __STDC_IEC_559__: "An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex."

Appendix F does not specify support of subnormal's and even has in 2 places describing functions:

... When subnormal results are supported, the returned value is exact and is independent of the current rounding direction mode. C17dr § F.10.7.2&3 2.

This at least implies subnormal support is not required for those functions. Also see @Ian Abbott


Nit:

"__STDC_IEC_559__ is not 1." is more like "__STDC_IEC_559__ not defined", not "if defined and not 1".

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • Thanks! So, `__STDC_IEC_559__ is 1` signifies that implementation does conform to the specifications in Annex F. Meaning that `__STDC_IEC_559__ is 1` != `conformance to IEEE 754`. Surprised. Unexpected. Confused. Can you comment on that? About "`__STDC_IEC_559__` is not 1": definition to `1` is not required by C11, Annex F. (In C11 why there is no consistency with logic for `__STDC__`, which is defined to 1 if an implementation is conforming?) However, this is changed in C17..C2x (N2479): if `__STDC_IEC_559__` is `1` , then an implementation conforms to the specifications in Annex F. – pmor Jul 03 '21 at 16:10
  • @pmor C17 (N2176) has "`__STDC_IEC_559__` The integer constant 1, intended to indicate conformance to the specifications in annex F (IEC 60559 floating-point arithmetic)." and "An implementation that defines `__STDC_IEC_559__` shall conform to the specifications in this annex." and "Implementations that do not define `__STDC_IEC_559__` are not required to conform to these specifications". Intention is certainly that if `__STDC_IEC_559__` defined and 1, then conformance to annex F, else then not defined. Defined and not 1 is murky. – chux - Reinstate Monica Jul 03 '21 at 17:19
  • @pmor There is a _lot_ to _conformance to IEEE 754_. So much so that a given compiler may choose to not define `__STDC_IEC_559__` even if it conform 100% to IEEE 754 and Annex F. It may not be worth it to prove Annex F conformity and maintain it. I expect a compiler that defines `__STDC_IEC_559__` to _all but 100%_ conform. Further, some conformity is expensive and so a compiler will offer options for _faster_ code that is nearly conforming. If you truly want 100.0% conformity, your compiler may need some certification, else it may be only close. – chux - Reinstate Monica Jul 03 '21 at 17:27
  • @pmor IMO, better to write code that tolerates marginally non-conforming implementations as I do not see 100% compliance as on going reality nor worth it (given reduce options). – chux - Reinstate Monica Jul 03 '21 at 17:28
  • "all but 100%": reminds me of scoring a 180 on the LSAT, which is extremely rare. Or "why you couldn't get 100? there is no 100". – pmor Jul 03 '21 at 18:00
  • @pmor 180? One better than [Elle Woods](https://www.imdb.com/title/tt0250494/). – chux - Reinstate Monica Jul 03 '21 at 18:03
  • x86 does not have `-to-` instructions. Leading to the fact that for `(char)` compilers generate `cvttss2si`, which does not raise Invalid floating-point exception for `(char)128.0`, which is IEEE 754-2008 violation. Does it mean that x86 is not IEEE 754-2008 conformant? – pmor Jul 05 '21 at 10:06
  • If `__STDC_IEC_559__ is` 1 != `conformance to IEC 60559 (IEEE 754)`, then why `__STDC_IEC_559__` instead of `__STDC_ANNEX_F__`? – pmor Jul 05 '21 at 10:09
  • @pmor "x86 is not IEEE 754-2008 conformant" --> Since one compiler does this, it does not mean all x86 compilers emit the same code. IAC, converting an out-of-char-range-`float` to `char` is "result is implementation-defined" (_implementation-defined_ is a spec _get out of jail free_ card), slog through compiler documentation and see what it reports. "why `__STDC_IEC_559__` instead of `__STDC_ANNEX_F__`" --> That would be a new unwise naming convention: naming a macro after some spec index. Such indexes may shift between specs. Should comments fail to answer, best to post a new question. – chux - Reinstate Monica Jul 05 '21 at 10:59
  • About conversion 'out of range floating-point to integer'. In C [it leads to UB](https://stackoverflow.com/q/66589100/1778275). In IEEE 754 it leads to WDB w.r.t. raising of exceptions: Invalid exception shall be raised. Now for `(char)128.0` gcc / clang generate code, which does not raise Invalid, which is a defect / bug. About 'new unwise naming convention': true, thanks for the hint. – pmor Jul 05 '21 at 15:33