Cygwin: math: Properly propagate input NANs in a few functions

While the C99 standard doesn't explicitly require this, the standard
says it is recommended (F.9.13).

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Martin Storsjö 2019-07-25 00:13:13 +03:00 committed by Ken Brown
parent a1c0608a88
commit 412965ab98
6 changed files with 20 additions and 8 deletions

View File

@ -50,7 +50,12 @@ __FLT_TYPE
__FLT_ABI(acosh) (__FLT_TYPE x)
{
int x_class = fpclassify (x);
if (x_class == FP_NAN || x < __FLT_CST(1.0))
if (x_class == FP_NAN)
{
errno = EDOM;
return x;
}
else if (x < __FLT_CST(1.0))
{
errno = EDOM;
return __FLT_NAN;

View File

@ -243,6 +243,9 @@ long double erfcl(long double a)
if (isinf (a))
return (signbit(a) ? 2.0 : 0.0);
if (isnan (a))
return (a);
x = fabsl (a);
if (x < 1.0L)

View File

@ -216,7 +216,7 @@ long double __lgammal_r(long double x, int* sgngaml)
*sgngaml = 1;
#ifdef NANS
if (isnanl(x))
return(NANL);
return x;
#endif
#ifdef INFINITIES
if (!isfinitel(x))

View File

@ -56,6 +56,8 @@ __FLT_ABI(log) (__FLT_TYPE x)
errno = ERANGE;
return -__FLT_HUGE_VAL;
}
else if (x_class == FP_NAN)
return x;
else if (signbit (x))
{
errno = EDOM;
@ -63,7 +65,5 @@ __FLT_ABI(log) (__FLT_TYPE x)
}
else if (x_class == FP_INFINITE)
return __FLT_HUGE_VAL;
else if (x_class == FP_NAN)
return __FLT_NAN;
return (__FLT_TYPE) __logl_internal ((long double) x);
}

View File

@ -121,9 +121,13 @@ __FLT_ABI(pow) (__FLT_TYPE x, __FLT_TYPE y)
return __FLT_CST(1.0);
else if (x_class == FP_NAN || y_class == FP_NAN)
{
rslt = (signbit(x) ? -__FLT_NAN : __FLT_NAN);
if (x_class == FP_NAN) {
errno = EDOM;
return rslt;
return x;
} else {
errno = EDOM;
return y;
}
}
else if (x_class == FP_ZERO)
{

View File

@ -272,7 +272,7 @@ long double __tgammal_r(long double x, int* sgngaml)
*sgngaml = 1;
#ifdef NANS
if (isnanl(x))
return (NANL);
return x;
#endif
#ifdef INFINITIES
#ifdef NANS