hypotl

Paul Zimmermann <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
       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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.