[Cfp-interest 2106] defect in ISO C about underflow with exact subnormal

Vincent Lefevre vincent at vinc17.net
Wed Aug 18 07:29:17 PDT 2021


On 2021-08-17 14:02:43 -0500, Rajan Bhakta wrote:
>     Jim: [CFP 1997]: Range error definitions of overflow and underflow.
>       See many CFP messages (Ex. CFP 2038-2090).
>       Re CFP 2090:
>       Jim: This would be a replacement of N2746.
>       Fred: An exact subnormal is an underflow.
>       Jim: Yes.
>       Fred: In 754 it may not raise the underflow exception.
>       Jim: Correct.
[...]

The IEEE 754 standard says:

  In addition, under default exception handling for underflow, if the
  rounded result is inexact — that is, it differs from what would have
  been computed were both exponent range and precision unbounded — the
  underflow flag shall be raised and the inexact (see 7.6) exception
  shall be signaled. If the rounded result is exact, no flag is raised
  and no inexact exception is signaled. This is the only case in this
  standard of an exception signal receiving default handling that does
  not raise the corresponding flag. Such an underflow signal has no
  observable effect under default handling.

Thus if the exception handling is not the default one, an exact
subnormal may yield non-default behavior.

In ISO C17 and the current C2x draft (N2596),
F.9.2 "Expression transformations":

  1 × x and x/1 → x     The expressions 1 × x, x/1, and x may be
                        regarded as equivalent (on IEC 60559 machines,
                        among others).399)

  399) Strict support for signaling NaNs — not required by this
  specification — would invalidate these and other transformations
  that remove arithmetic operators.

is incorrect under non-default exception handling, because if x is
a subnormal, 1 × x and x/1 may have a behavior different from just
returning x.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list