public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix large ulp error in pow without fma very near 1.0 Date: Fri, 06 Jul 2018 08:45:00 -0000 [thread overview] Message-ID: <20180706084500.72930.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2805b07fa1f54ef001c2ce78618e8efc87155232 commit 2805b07fa1f54ef001c2ce78618e8efc87155232 Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Tue Jul 3 13:05:31 2018 +0100 Fix large ulp error in pow without fma very near 1.0 The !HAVE_FAST_FMA code path split r = z/c - 1 into r = rhi + rlo such that when z = 1-tiny and c = 1 then rlo and rhi could have much larger magnitude than r which later caused large rounding errors. So do a nearest rounding instead of truncation at the split. In newlib with default settings this was observable on some arm targets that enable the new math code but has no fma. Diff: --- newlib/libm/common/pow.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/newlib/libm/common/pow.c b/newlib/libm/common/pow.c index 11964e3..a5504e5 100644 --- a/newlib/libm/common/pow.c +++ b/newlib/libm/common/pow.c @@ -79,11 +79,13 @@ log_inline (uint64_t ix, double_t *tail) logc = T[i].logc; logctail = T[i].logctail; - /* r = z/c - 1, arranged to be exact. */ + /* Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and + |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible. */ #if HAVE_FAST_FMA r = fma (z, invc, -1.0); #else - double_t zhi = asdouble (iz & (-1ULL << 32)); + /* Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|. */ + double_t zhi = asdouble ((iz + (1ULL << 31)) & (-1ULL << 32)); double_t zlo = z - zhi; double_t rhi = zhi * invc - 1.0; double_t rlo = zlo * invc;
reply other threads:[~2018-07-06 8:45 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=20180706084500.72930.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=newlib-cvs@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: linkBe 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).