public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Paul Zimmermann <Paul.Zimmermann@inria.fr>
To: newlib@sourceware.org
Subject: hypotl
Date: Thu, 14 Jan 2021 08:13:23 +0100	[thread overview]
Message-ID: <mw1reouh2k.fsf@tomate.loria.fr> (raw)

       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

                 reply	other threads:[~2021-01-14  7:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mw1reouh2k.fsf@tomate.loria.fr \
    --to=paul.zimmermann@inria.fr \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).