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 error in fdim/f for infinities Date: Tue, 10 Mar 2020 14:46:46 +0000 (GMT) [thread overview] Message-ID: <20200310144646.1398A3947413@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=18b4e0e5187f7e2076661e53747977f21dabedff commit 18b4e0e5187f7e2076661e53747977f21dabedff Author: Fabian Schriever <fabian.schriever@gtd-gmbh.de> Date: Tue Mar 10 11:24:12 2020 +0100 Fix error in fdim/f for infinities The comparison c == FP_INFINITE causes the function to return +inf as it expects x = +inf to always be larger than y. This shortcut causes several issues as it also returns +inf for the following cases: - fdim(+inf, +inf), expected (as per C99): +0.0 - fdim(-inf, any non NaN), expected: +0.0 I don't see a reason to keep the comparison as all the infinity cases return the correct result using just the ternary operation. Diff: --- newlib/libm/common/s_fdim.c | 5 +---- newlib/libm/common/sf_fdim.c | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/newlib/libm/common/s_fdim.c b/newlib/libm/common/s_fdim.c index 73a027953..61a4908f3 100644 --- a/newlib/libm/common/s_fdim.c +++ b/newlib/libm/common/s_fdim.c @@ -49,11 +49,8 @@ ANSI C, POSIX. double y; #endif { - int c = __fpclassifyd(x); - if (c == FP_NAN) return(x); + if (__fpclassifyd(x) == FP_NAN) return(x); if (__fpclassifyd(y) == FP_NAN) return(y); - if (c == FP_INFINITE) - return HUGE_VAL; return x > y ? x - y : 0.0; } diff --git a/newlib/libm/common/sf_fdim.c b/newlib/libm/common/sf_fdim.c index fe349098b..8fee57002 100644 --- a/newlib/libm/common/sf_fdim.c +++ b/newlib/libm/common/sf_fdim.c @@ -14,11 +14,8 @@ float y; #endif { - int c = __fpclassifyf(x); - if (c == FP_NAN) return(x); + if (__fpclassifyf(x) == FP_NAN) return(x); if (__fpclassifyf(y) == FP_NAN) return(y); - if (c == FP_INFINITE) - return HUGE_VALF; return x > y ? x - y : 0.0; }
reply other threads:[~2020-03-10 14:46 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=20200310144646.1398A3947413@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).