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>
This commit is contained in:
Keith Packard via Newlib 2020-08-04 15:22:21 -07:00 committed by Corinna Vinschen
parent 905aa4c013
commit 2eafcc78df
6 changed files with 52 additions and 42 deletions

View File

@ -128,17 +128,19 @@ None of the Bessel functions are in ANSI C.
double z; double z;
z = __ieee754_y0(x); z = __ieee754_y0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){ if(x < 0.0){
/* y0(0) = -inf or y0(x<0) = NaN */ /* y0(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VAL; }
if(x == 0.0){
/* y0(0) = -inf */
errno = ERANGE;
} }
if(x>X_TLOSS) { if(x>X_TLOSS) {
/* y0(x>X_TLOSS) */ /* y0(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0; }
} else return z;
return z;
#endif #endif
} }

View File

@ -55,17 +55,19 @@
double z; double z;
z = __ieee754_y1(x); z = __ieee754_y1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){ if(x < 0.0){
/* y1(0) = -inf or y1(x<0) = NaN */ /* y1(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VAL; }
if(x == 0.0){
/* y1(0) = -inf */
errno = ERANGE;
} }
if(x>X_TLOSS) { if(x>X_TLOSS) {
/* y1(x>X_TLOSS) */ /* y1(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0; }
} else return z;
return z;
#endif #endif
} }

View File

@ -77,17 +77,19 @@
double z; double z;
z = __ieee754_yn(n,x); z = __ieee754_yn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){ if(x < 0.0){
/* yn(n,0) = -inf or yn(x<0) = NaN */ /* yn(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VAL; }
if(x == 0.0){
/* yn(0) = -inf */
errno = ERANGE;
} }
if(x>X_TLOSS) { if(x>X_TLOSS) {
/* yn(x>X_TLOSS) */ /* yn(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0; }
} else return z;
return z;
#endif #endif
} }

View File

@ -35,9 +35,8 @@
if(fabsf(x)>(float)X_TLOSS) { if(fabsf(x)>(float)X_TLOSS) {
/* j0f(|x|>X_TLOSS) */ /* j0f(|x|>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0f; }
} else return z;
return z;
#endif #endif
} }
@ -54,17 +53,19 @@
float z; float z;
z = __ieee754_y0f(x); z = __ieee754_y0f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= (float)0.0){ if(x < 0.0f){
/* y0f(0) = -inf or y0f(x<0) = NaN */ /* y0f(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VALF;
} }
if (x == 0.0f){
/* y0f(n,0) = -inf */
errno = ERANGE;
}
if(x>(float)X_TLOSS) { if(x>(float)X_TLOSS) {
/* y0f(x>X_TLOSS) */ /* y0f(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0f; }
} else return z;
return z;
#endif #endif
} }

View File

@ -56,17 +56,19 @@
float z; float z;
z = __ieee754_y1f(x); z = __ieee754_y1f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0f){ if(x < 0.0f){
/* y1f(0) = -inf or y1f(x<0) = NaN */ /* y1f(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VALF;
} }
if (x == 0.0f){
/* y1f(n,0) = -inf */
errno = ERANGE;
}
if(x>(float)X_TLOSS) { if(x>(float)X_TLOSS) {
/* y1f(x>X_TLOSS) */ /* y1f(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0f; }
} else return z;
return z;
#endif #endif
} }

View File

@ -33,9 +33,8 @@
if(fabsf(x)>(float)X_TLOSS) { if(fabsf(x)>(float)X_TLOSS) {
/* jnf(|x|>X_TLOSS) */ /* jnf(|x|>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0f; }
} else return z;
return z;
#endif #endif
} }
@ -52,17 +51,19 @@
float z; float z;
z = __ieee754_ynf(n,x); z = __ieee754_ynf(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0f){ if(x < 0.0f){
/* ynf(n,0) = -inf or ynf(x<0) = NaN */ /* ynf(x<0) = NaN */
errno = EDOM; errno = EDOM;
return -HUGE_VALF;
} }
if (x == 0.0f){
/* ynf(n,0) = -inf */
errno = ERANGE;
}
if(x>(float)X_TLOSS) { if(x>(float)X_TLOSS) {
/* ynf(x>X_TLOSS) */ /* ynf(x>X_TLOSS) */
errno = ERANGE; errno = ERANGE;
return 0.0f; }
} else return z;
return z;
#endif #endif
} }