public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* hypotl
@ 2021-01-14  7:13 Paul Zimmermann
  0 siblings, 0 replies; only message in thread
From: Paul Zimmermann @ 2021-01-14  7:13 UTC (permalink / raw)
  To: newlib

       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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-14  7:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14  7:13 hypotl Paul Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).