From: Paul Zimmermann <Paul.Zimmermann@inria.fr>
To: newlib@sourceware.org
Cc: tydeman@tybor.com
Subject: ldexp with directed rounding
Date: Mon, 27 Feb 2023 17:35:26 +0100 [thread overview]
Message-ID: <mwfsarrrqp.fsf@coriandre.loria.fr> (raw)
Hi,
it seems that Newlib does not honor the rounding mode for ldexp(0x1p-1074,-1):
for rounding updwards it should return 0x1p-1074 and not 0.
Test program:
#include <stdio.h>
#include <math.h>
#include <fenv.h>
int main()
{
volatile double x = 1.0, y;
while (x * 0.5 != 0)
x = x * 0.5;
fesetround (FE_TONEAREST);
y = ldexp (x, -1);
printf ("FE_TONEAREST: y=%la\n", y);
fesetround (FE_TOWARDZERO);
y = ldexp (x, -1);
printf ("FE_TOWARDZERO: y=%la\n", y);
fesetround (FE_UPWARD);
y = ldexp (x, -1);
printf ("FE_UPWARD: y=%la\n", y);
fesetround (FE_DOWNWARD);
y = ldexp (x, -1);
printf ("FE_DOWNWARD: y=%la\n", y);
}
With newlib-4.3.0.20230120 on x86_64:
zimmerma@salade:~/svn/tbd/20/src/binary64$ gcc -fno-builtin check_ldexp.c /localdisk/zimmerma/${NEWLIB}/libm.a
zimmerma@salade:~/svn/tbd/20/src/binary64$ ./a.out
FE_TONEAREST: y=0x0p+0
FE_TOWARDZERO: y=0x0p+0
FE_UPWARD: y=0x0p+0
FE_DOWNWARD: y=0x0p+0
With GNU libc:
zimmerma@salade:~/svn/tbd/20/src/binary64$ gcc -fno-builtin check_ldexp.c -lm
zimmerma@salade:~/svn/tbd/20/src/binary64$ ./a.out
FE_TONEAREST: y=0x0p+0
FE_TOWARDZERO: y=0x0p+0
FE_UPWARD: y=0x0.0000000000001p-1022
FE_DOWNWARD: y=0x0p+0
This test was suggested by Fred Tydeman.
Paul
reply other threads:[~2023-02-27 16:35 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=mwfsarrrqp.fsf@coriandre.loria.fr \
--to=paul.zimmermann@inria.fr \
--cc=newlib@sourceware.org \
--cc=tydeman@tybor.com \
/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).