public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Andoni Arregi <andoni.arregui@gtd-gmbh.de>
To: newlib@sourceware.org
Cc: Andoni Arregi <andoni.arregui@gtd-gmbh.de>
Subject: [PATCH 3/4] Compare j as unsigned
Date: Wed, 12 Apr 2023 17:34:44 +0200	[thread overview]
Message-ID: <20230412153445.161047-4-andoni.arregui@gtd-gmbh.de> (raw)
In-Reply-To: <20230412153445.161047-1-andoni.arregui@gtd-gmbh.de>

j is int32_t and thus j<<31 is undefined if j==1.

Taken from FreeBSD commit bdd8abc6d6a93ce3ab8ad5db716222ee3110c4a3
---
 newlib/libm/math/e_pow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libm/math/e_pow.c b/newlib/libm/math/e_pow.c
index f24a98f6e..0e2251f10 100644
--- a/newlib/libm/math/e_pow.c
+++ b/newlib/libm/math/e_pow.c
@@ -141,7 +141,7 @@ ivln2_l  =  1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
 		k = (iy>>20)-0x3ff;	   /* exponent */
 		if(k>20) {
 		    j = ly>>(52-k);
-		    if((j<<(52-k))==ly) yisint = 2-(j&1);
+		    if(((uint32_t)j<<(52-k))==ly) yisint = 2-(j&1);
 		} else if(ly==0) {
 		    j = iy>>(20-k);
 		    if((j<<(20-k))==iy) yisint = 2-(j&1);
-- 
2.40.0



  parent reply	other threads:[~2023-04-12 15:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 15:34 [PATCH 0/4] Fix huge error for pow detected by Paul Zimmermann Andoni Arregi
2023-04-12 15:34 ` [PATCH 1/4] Fix missing sign for overflow/underflow where x is negative and y is large odd integer Andoni Arregi
2023-04-12 15:34 ` [PATCH 2/4] Fix x close to 1, y between 2^31 and 2^64 Andoni Arregi
2023-04-12 15:34 ` Andoni Arregi [this message]
2023-04-12 15:34 ` [PATCH 4/4] Replace always true if with else Andoni Arregi
2023-04-13  5:46 ` [PATCH 0/4] Fix huge error for pow detected by Paul Zimmermann Paul Zimmermann
2023-04-13 12:16 ` Paul Zimmermann
2023-04-13 14:39   ` Andoni Arregi
2023-04-13 17:37     ` Jeff Johnston

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=20230412153445.161047-4-andoni.arregui@gtd-gmbh.de \
    --to=andoni.arregui@gtd-gmbh.de \
    --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).