[Cfp-interest 1951] inexact exception

Paul Zimmermann Paul.Zimmermann at inria.fr
Wed Apr 7 08:12:03 PDT 2021


       Hello,

question: should the inexact exception be correctly raised (or not) for
mathematical functions?

In http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf, section F.10,
note 10 says:

"Whether or when library functions not bound to operations in IEC 60559 raise the "inexact" floating-point exception is unspecified, unless stated otherwise."

Since hypot is described in F.10.4.4, I understand it is bound to operations
in IEC 60559, thus it should correctly raise inexact.

$ cat hypot.c
#include <stdio.h>
#include <fenv.h>
#include <math.h>

int main()
{
  double x, y, z;
  x = 1235216565974040.0;
  y = x + 1.0;
  printf ("x=%.6f y=%.6f\n", x, y);
  printf ("inexact: %d\n", fetestexcept (FE_INEXACT));
  z = hypot (x, y);
  printf ("z=%.6f\n", z);
  printf ("inexact: %d\n", fetestexcept (FE_INEXACT));
}

$ gcc -fno-builtin hypot.c -lm
$ ./a.out
x=1235216565974040.000000 y=1235216565974041.000000
inexact: 0
z=1746860020068409.000000
inexact: 32

x is a Pythagorean number, such that x^2+(x+1)^2 is an exact square,
thus we should expect that the inexact flag remains zero.

Is my reasoning correct?

Best regards,
Paul


More information about the Cfp-interest mailing list