public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Richard Allen <rsaxvc@rsaxvc.net>
To: newlib@sourceware.org
Subject: Re: [PATCH] Avoid extra float->double conversion
Date: Thu, 20 Apr 2017 00:03:00 -0000	[thread overview]
Message-ID: <CAMY0PLUCOrGeeKZ2HYNPDygXMA+R3PnTM0qZDTYpywN6HHmThg@mail.gmail.com> (raw)
In-Reply-To: <CAMY0PLVpmE2_5WL2jZLq8M=Zv-EE6f7u8VE0hy1gX4T7vCYvSw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

There were a few more spots triggering double-precision math.
Attached patch updated to include comparisons and multiplies.

On Wed, Apr 19, 2017 at 6:53 PM, Richard Allen <rsaxvc@rsaxvc.net> wrote:
> Patch avoids an unnecessary float->double
> conversion to save a small amount of codespace.
>
> -Richard

[-- Attachment #2: 0002-Remove-extra-double-precision-rounding-and-compariso.patch --]
[-- Type: text/x-patch, Size: 1221 bytes --]

From 361abc1541b9a0f76a018a92b7e9d1e561cc35e8 Mon Sep 17 00:00:00 2001
From: Richard <rsaxvc@rsaxvc.net>
Date: Wed, 19 Apr 2017 18:37:17 -0500
Subject: [PATCH 2/2] Remove extra double-precision rounding and comparisons

Replace rint() with rintf() to avoid unnecessary
increase in precision, use float constants
to avoid doing compare, conversion, and multiplication
using doubles.
---
 newlib/libm/math/wf_pow.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
index bd9de0ad0..b92e47d8e 100644
--- a/newlib/libm/math/wf_pow.c
+++ b/newlib/libm/math/wf_pow.c
@@ -125,12 +125,12 @@
 		    exc.arg2 = (double)y;
 		    if (_LIB_VERSION == _SVID_) {
 		       exc.retval = HUGE;
-		       y *= 0.5;
-		       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE;
+		       y *= 0.5f;
+		       if(x<0.0f&&rintf(y)!=y) exc.retval = -HUGE;
 		    } else {
 		       exc.retval = HUGE_VAL;
-                       y *= 0.5;
-		       if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
+                       y *= 0.5f;
+		       if(x<0.0f&&rintf(y)!=y) exc.retval = -HUGE_VAL;
 		    }
 		    if (_LIB_VERSION == _POSIX_)
 		        errno = ERANGE;
-- 
2.11.0


  reply	other threads:[~2017-04-20  0:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 23:53 Richard Allen
2017-04-20  0:03 ` Richard Allen [this message]
2017-04-20  0:36   ` Craig Howland
2017-04-21 13:30     ` Richard Allen
2017-05-18 23:58       ` Richard Allen

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=CAMY0PLUCOrGeeKZ2HYNPDygXMA+R3PnTM0qZDTYpywN6HHmThg@mail.gmail.com \
    --to=rsaxvc@rsaxvc.net \
    --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).