hypotl

Paul Zimmermann Paul.Zimmermann@inria.fr
Thu Jan 14 07:13:23 GMT 2021


       Hi,

it seems newlib only provides sqrtl and hypotl for double extended precision
(long double on x86_64). Please can you confirm?

However the hypotl function seems buggy for large inputs, where it returns +Inf:

$ cat test_hypot.c
#include <stdio.h>
#include <math.h>

#ifdef NEWLIB
/* without this, newlib says: undefined reference to `__errno' */
int errno;
int* __errno () { return &errno; }
#endif

int main()
{
  long double x = 0xf.ffffffffffffffep+8188l;
  long double y = (long double) 0;
  long double z = hypotl (x, y);
  printf ("x=%La y=%La z=%La\n", x, y, z);
  x = 0xf.fffffffffffffffp+8188l;
  z = hypotl (x, y);
  printf ("x=%La y=%La z=%La\n", x, y, z);
  x = 0x1p+8192l;
  z = hypotl (x, y);
  printf ("x=%La y=%La z=%La\n", x, y, z);
  return 0;
}

$ gcc -DNEWLIB test_hypot.c /localdisk/zimmerma/newlib-4.1.0/libm.a -lm
$ ./a.out
x=0xf.ffffffffffffffep+8188 y=0x0p+0 z=0xf.ffffffffffffffep+8188
x=0xf.fffffffffffffffp+8188 y=0x0p+0 z=-0xcp+16380
x=0x8p+8189 y=0x0p+0 z=inf

Note also the case x=0xf.fffffffffffffffp+8188 y=0x0p+0 where it returns an
ill-formed number.

Best regards,
Paul


More information about the Newlib mailing list