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] libm/math: Make yx functions set errno=ERANGE for x=0
Date: Wed, 5 Aug 2020 20:43:11 +0000 (GMT) [thread overview]
Message-ID: <20200805204311.7B9563860C33@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe
commit 2eafcc78dfe6d356a8d6debe439c8aa9839b1dbe
Author: Keith Packard via Newlib <newlib@sourceware.org>
Date: Tue Aug 4 15:22:21 2020 -0700
libm/math: Make yx functions set errno=ERANGE for x=0
The y0, y1 and yn functions need separate conditions when x is zero as
that returns ERANGE instead of EDOM.
Also stop adjusting the return value from the __ieee754_y* functions
as that is already correct and we were just breaking it.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diff:
---
newlib/libm/math/w_j0.c | 14 ++++++++------
newlib/libm/math/w_j1.c | 14 ++++++++------
newlib/libm/math/w_jn.c | 14 ++++++++------
newlib/libm/math/wf_j0.c | 19 ++++++++++---------
newlib/libm/math/wf_j1.c | 14 ++++++++------
newlib/libm/math/wf_jn.c | 19 ++++++++++---------
6 files changed, 52 insertions(+), 42 deletions(-)
diff --git a/newlib/libm/math/w_j0.c b/newlib/libm/math/w_j0.c
index b537ef406..47063ff6f 100644
--- a/newlib/libm/math/w_j0.c
+++ b/newlib/libm/math/w_j0.c
@@ -128,17 +128,19 @@ None of the Bessel functions are in ANSI C.
double z;
z = __ieee754_y0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= 0.0){
- /* y0(0) = -inf or y0(x<0) = NaN */
+ if(x < 0.0){
+ /* y0(x<0) = NaN */
errno = EDOM;
- return -HUGE_VAL;
+ }
+ if(x == 0.0){
+ /* y0(0) = -inf */
+ errno = ERANGE;
}
if(x>X_TLOSS) {
/* y0(x>X_TLOSS) */
errno = ERANGE;
- return 0.0;
- } else
- return z;
+ }
+ return z;
#endif
}
diff --git a/newlib/libm/math/w_j1.c b/newlib/libm/math/w_j1.c
index 6f25fea27..0912b6776 100644
--- a/newlib/libm/math/w_j1.c
+++ b/newlib/libm/math/w_j1.c
@@ -55,17 +55,19 @@
double z;
z = __ieee754_y1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= 0.0){
- /* y1(0) = -inf or y1(x<0) = NaN */
+ if(x < 0.0){
+ /* y1(x<0) = NaN */
errno = EDOM;
- return -HUGE_VAL;
+ }
+ if(x == 0.0){
+ /* y1(0) = -inf */
+ errno = ERANGE;
}
if(x>X_TLOSS) {
/* y1(x>X_TLOSS) */
errno = ERANGE;
- return 0.0;
- } else
- return z;
+ }
+ return z;
#endif
}
diff --git a/newlib/libm/math/w_jn.c b/newlib/libm/math/w_jn.c
index 28a9abc07..4e770ea5c 100644
--- a/newlib/libm/math/w_jn.c
+++ b/newlib/libm/math/w_jn.c
@@ -77,17 +77,19 @@
double z;
z = __ieee754_yn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= 0.0){
- /* yn(n,0) = -inf or yn(x<0) = NaN */
+ if(x < 0.0){
+ /* yn(x<0) = NaN */
errno = EDOM;
- return -HUGE_VAL;
+ }
+ if(x == 0.0){
+ /* yn(0) = -inf */
+ errno = ERANGE;
}
if(x>X_TLOSS) {
/* yn(x>X_TLOSS) */
errno = ERANGE;
- return 0.0;
- } else
- return z;
+ }
+ return z;
#endif
}
diff --git a/newlib/libm/math/wf_j0.c b/newlib/libm/math/wf_j0.c
index 4d125db79..ed21a01f5 100644
--- a/newlib/libm/math/wf_j0.c
+++ b/newlib/libm/math/wf_j0.c
@@ -35,9 +35,8 @@
if(fabsf(x)>(float)X_TLOSS) {
/* j0f(|x|>X_TLOSS) */
errno = ERANGE;
- return 0.0f;
- } else
- return z;
+ }
+ return z;
#endif
}
@@ -54,17 +53,19 @@
float z;
z = __ieee754_y0f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= (float)0.0){
- /* y0f(0) = -inf or y0f(x<0) = NaN */
+ if(x < 0.0f){
+ /* y0f(x<0) = NaN */
errno = EDOM;
- return -HUGE_VALF;
}
+ if (x == 0.0f){
+ /* y0f(n,0) = -inf */
+ errno = ERANGE;
+ }
if(x>(float)X_TLOSS) {
/* y0f(x>X_TLOSS) */
errno = ERANGE;
- return 0.0f;
- } else
- return z;
+ }
+ return z;
#endif
}
diff --git a/newlib/libm/math/wf_j1.c b/newlib/libm/math/wf_j1.c
index e178273c5..a4609ba28 100644
--- a/newlib/libm/math/wf_j1.c
+++ b/newlib/libm/math/wf_j1.c
@@ -56,17 +56,19 @@
float z;
z = __ieee754_y1f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= 0.0f){
- /* y1f(0) = -inf or y1f(x<0) = NaN */
+ if(x < 0.0f){
+ /* y1f(x<0) = NaN */
errno = EDOM;
- return -HUGE_VALF;
}
+ if (x == 0.0f){
+ /* y1f(n,0) = -inf */
+ errno = ERANGE;
+ }
if(x>(float)X_TLOSS) {
/* y1f(x>X_TLOSS) */
errno = ERANGE;
- return 0.0f;
- } else
- return z;
+ }
+ return z;
#endif
}
diff --git a/newlib/libm/math/wf_jn.c b/newlib/libm/math/wf_jn.c
index 3e4632ead..b82346d79 100644
--- a/newlib/libm/math/wf_jn.c
+++ b/newlib/libm/math/wf_jn.c
@@ -33,9 +33,8 @@
if(fabsf(x)>(float)X_TLOSS) {
/* jnf(|x|>X_TLOSS) */
errno = ERANGE;
- return 0.0f;
- } else
- return z;
+ }
+ return z;
#endif
}
@@ -52,17 +51,19 @@
float z;
z = __ieee754_ynf(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
- if(x <= 0.0f){
- /* ynf(n,0) = -inf or ynf(x<0) = NaN */
+ if(x < 0.0f){
+ /* ynf(x<0) = NaN */
errno = EDOM;
- return -HUGE_VALF;
}
+ if (x == 0.0f){
+ /* ynf(n,0) = -inf */
+ errno = ERANGE;
+ }
if(x>(float)X_TLOSS) {
/* ynf(x>X_TLOSS) */
errno = ERANGE;
- return 0.0f;
- } else
- return z;
+ }
+ return z;
#endif
}
reply other threads:[~2020-08-05 20:43 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=20200805204311.7B9563860C33@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: 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).