From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id A4B78385E009 for ; Thu, 26 Mar 2020 00:18:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A4B78385E009 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id A38073F2B6CA for ; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4NRzdtrwRZ6F; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 58FDB3F2B63D; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id C11E91582186; Wed, 25 Mar 2020 17:18:23 -0700 (PDT) From: Keith Packard To: newlib@sourceware.org Subject: [PATCH 3/3] newlib/libm/math: Make pow/powf return qnan for snan arg Date: Wed, 25 Mar 2020 17:18:21 -0700 Message-Id: <20200326001821.174426-4-keithp@keithp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326001821.174426-1-keithp@keithp.com> References: <20200326001821.174426-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-26.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 00:18:27 -0000 The IEEE spec for pow only has special case for x**0 and 1**y when x/y are quiet NaN. For signaling NaN, the general case applies and these functions should signal the invalid exception and return a quiet NaN. Signed-off-by: Keith Packard --- newlib/libm/math/e_pow.c | 13 +++++++++---- newlib/libm/math/ef_pow.c | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/newlib/libm/math/e_pow.c b/newlib/libm/math/e_pow.c index 5fd28e65f..4c450ec05 100644 --- a/newlib/libm/math/e_pow.c +++ b/newlib/libm/math/e_pow.c @@ -58,6 +58,8 @@ */ #include "fdlibm.h" +#include "math_config.h" + #if __OBSOLETE_MATH #ifndef _DOUBLE_IS_32BITS @@ -116,14 +118,17 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ EXTRACT_WORDS(hy,ly,y); ix = hx&0x7fffffff; iy = hy&0x7fffffff; - /* y==zero: x**0 = 1 */ - if((iy|ly)==0) return one; + /* y==zero: x**0 = 1 unless x is snan */ + if((iy|ly)==0) { + if (issignaling_inline(x)) return x + y; + return one; + } /* x|y==NaN return NaN unless x==1 then return 1 */ if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) { - if(((hx-0x3ff00000)|lx)==0) return one; - else return nan(""); + if(((hx-0x3ff00000)|lx)==0 && !issignaling_inline(y)) return one; + else return x + y; } /* determine if y is an odd int when x < 0 diff --git a/newlib/libm/math/ef_pow.c b/newlib/libm/math/ef_pow.c index d9e85a95e..d4ea4c5e8 100644 --- a/newlib/libm/math/ef_pow.c +++ b/newlib/libm/math/ef_pow.c @@ -14,6 +14,7 @@ */ #include "fdlibm.h" +#include "math_config.h" #if __OBSOLETE_MATH #ifdef __v810__ @@ -74,13 +75,16 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ ix = hx&0x7fffffff; iy = hy&0x7fffffff; /* y==zero: x**0 = 1 */ - if(FLT_UWORD_IS_ZERO(iy)) return one; + if(FLT_UWORD_IS_ZERO(iy)) { + if (issignalingf_inline(x)) return x + y; + return one; + } /* x|y==NaN return NaN unless x==1 then return 1 */ if(FLT_UWORD_IS_NAN(ix) || FLT_UWORD_IS_NAN(iy)) { - if(hx==0x3f800000) return one; - else return nanf(""); + if(hx==0x3f800000 && !issignalingf_inline(y)) return one; + else return x + y; } /* determine if y is an odd int when x < 0 -- 2.25.1