From: Keith Packard <keithp@keithp.com>
To: newlib@sourceware.org
Subject: [PATCH 2/3] newlib/libm/common: Don't re-convert float to bits in modf/modff
Date: Wed, 25 Mar 2020 17:18:20 -0700 [thread overview]
Message-ID: <20200326001821.174426-3-keithp@keithp.com> (raw)
In-Reply-To: <20200326001821.174426-1-keithp@keithp.com>
These functions shared a pattern of re-converting the argument to bits
when returning +/-0. Skip that as the initial conversion still has the
sign bit.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/libm/common/s_modf.c | 12 +++---------
newlib/libm/common/sf_modf.c | 8 ++------
2 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/newlib/libm/common/s_modf.c b/newlib/libm/common/s_modf.c
index c826580b4..e552a9460 100644
--- a/newlib/libm/common/s_modf.c
+++ b/newlib/libm/common/s_modf.c
@@ -81,10 +81,8 @@ QUICKREF
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) { /* x is integral */
- __uint32_t high;
*iptr = x;
- GET_HIGH_WORD(high,x);
- INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
return x;
} else {
INSERT_WORDS(*iptr,i0&(~i),0);
@@ -92,19 +90,15 @@ QUICKREF
}
}
} else if (j0>51) { /* no fraction part */
- __uint32_t high;
*iptr = x;
if (__fpclassifyd(x) == FP_NAN) return *iptr = x+x; /* x is NaN, return NaN */
- GET_HIGH_WORD(high,x);
- INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
return x;
} else { /* fraction part in low x */
i = ((__uint32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) { /* x is integral */
- __uint32_t high;
*iptr = x;
- GET_HIGH_WORD(high,x);
- INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
+ INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
return x;
} else {
INSERT_WORDS(*iptr,i0,i1&(~i));
diff --git a/newlib/libm/common/sf_modf.c b/newlib/libm/common/sf_modf.c
index e241e4612..2994378bb 100644
--- a/newlib/libm/common/sf_modf.c
+++ b/newlib/libm/common/sf_modf.c
@@ -33,10 +33,8 @@
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) { /* x is integral */
- __uint32_t ix;
*iptr = x;
- GET_FLOAT_WORD(ix,x);
- SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
+ SET_FLOAT_WORD(x,i0&0x80000000); /* return +-0 */
return x;
} else {
SET_FLOAT_WORD(*iptr,i0&(~i));
@@ -44,11 +42,9 @@
}
}
} else { /* no fraction part */
- __uint32_t ix;
*iptr = x;
if (__fpclassifyf(x) == FP_NAN) return *iptr = x+x; /* x is NaN, return NaN */
- GET_FLOAT_WORD(ix,x);
- SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
+ SET_FLOAT_WORD(x,i0&0x80000000); /* return +-0 */
return x;
}
}
--
2.25.1
next prev parent reply other threads:[~2020-03-26 0:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-26 0:18 NaN fixes in pow, powf, modf, modff Keith Packard
2020-03-26 0:18 ` [PATCH 1/3] newlib/libm/common: Fix modf/modff returning snan Keith Packard
2020-03-26 0:18 ` Keith Packard [this message]
2020-03-26 0:18 ` [PATCH 3/3] newlib/libm/math: Make pow/powf return qnan for snan arg Keith Packard
2020-03-26 11:42 ` NaN fixes in pow, powf, modf, modff Corinna Vinschen
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=20200326001821.174426-3-keithp@keithp.com \
--to=keithp@keithp.com \
--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).