'Why does IEEE 754 categorize convertFromInt and convertToIntegerXXX as arithmetic operations and not conversion operations?

IEEE Std 754-2019:

5.4.1 Arithmetic operations

― formatOf-convertFromInt(int)

― intFormatOf-convertToIntegerXXX(source)

Question: why convertFromInt and convertToIntegerXXX are categorized as arithmetic operations and not conversion operations?

The reason forthe question:

C11 (emphasis added):

5.2.4.2.2 Characteristics of floating types <float.h>

3 A quiet NaN propagates through almost every _arithmetic operation without raising a floating-point exception; a signaling NaN generally raises a floating-point exception when occurring as an arithmetic operand.

According to IEEE 754 (both 2008 and 2019) convertFromInt and convertToIntegerXXX are categorized as arithmetic operations and not conversion operations.

According to C11 (emphasis added):

F.4 Floating to integer conversion

1 ... Otherwise, if the floating value is infinite or NaN or if the integral part of the floating value exceeds the range of the integer type, then the ‘‘invalid’’ floating-point exception is raised and the resulting value is unspecified. ...

Here NaN is not specialized, hence, we conclude that NaN here is any NaN.

Also C11 (emphasis added):

F.3 Operators and functions

The lrint and llrint functions in <math.h> provide the IEC 60559 conversions ... The lrint and llrint functions can be used to implement IEC 60559 conversions from floating to other integer formats.

However, according to IEEE 754 (both 2008 and 2019) convertFromInt and convertToIntegerXXX are categorized as arithmetic operations and not conversion operations.

Overall: I am confused. I see the contradiction between C11 and IEEE 754.

Code sample:

l = (long)NAN; // shall lead to raising of FE_INVALID ??

Here:

  1. IEEE 754 says: convertToIntegerXXX is categorized as arithmetic operations AND C11 says: quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception.
  2. C11 says: if the floating value is infinite or NaN or if the integral part of the floating value exceeds the range of the integer type, then the ‘‘invalid’’ floating-point exception is raised`.

Core question: Shall l = (long)NAN lead to raising of FE_INVALID?

Extra question: IEEE 754: are convertFromInt and convertToIntegerXXX incorrectly categorized as arithmetic operations instead of being categorized as conversion operations?

It seems that indeed IEEE 754 incorrectly categorizes them. For l = (long)NAN clang 13.0.0 for x86_64 generates cvttss2si, which raises invalid floating-point exception. Note: gcc 11.2 still ignores #pragma STDC FENV_ACCESS.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source