Updates for ccosh[f] and csinh[f]

* lib/msun/src/s_ccosh.c:
  . Update Copyright years.
  . sin() and cos() are needed at the same time, so use sincos() to
    compute values.  This does argument reduction once instead of twice.
  . Replace '* 0.5' with '/ 2'. This reduces diff with s_ccoshf.c.
  . For (LDBL_MANT_DIG == 53), add weak references for ccoshl and ccosl.

* lib/msun/src/s_ccoshf.c:
  . Update Copyright years.
  . sin() and cos() are needed at the same time, so use sincos() to
    compute values.  This does argument reduction once instead of twice.
  . Replace '* 0.5F' with '/ 2'. This reduces diff with s_ccoshf.c.

* lib/msun/src/s_csinh.c:
  . Update Copyright years.
  . sin() and cos() are needed at the same time, so use sincos() to
    compute values.  This does argument reduction once instead of twice.
  . Replace '* 0.5' with '/ 2'. This reduces diff with s_csinhf.c.
  . For (LDBL_MANT_DIG == 53), add weak references for csinhl and csinl.

* lib/msun/src/s_csinhf.c:
  . Update Copyright years.
  . sin() and cos() are needed at the same time, so use sincos() to
    compute values.  This does argument reduction once instead of twice.
  . Replace '* 0.5F' with '/ 2'. This reduces diff with s_ccoshf.c.

PR:		288740
MFC after:	1 week
This commit is contained in:
Steve Kargl
2025-08-09 19:28:07 +02:00
committed by Dimitry Andric
parent 53b77089e5
commit a1d051bc87
4 changed files with 54 additions and 28 deletions
+16 -7
View File
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
* Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static const double huge = 0x1p1023;
double complex
ccosh(double complex z)
{
double x, y, h;
double c, h, s, x, y;
int32_t hx, hy, ix, iy, lx, ly;
x = creal(z);
@@ -64,14 +64,16 @@ ccosh(double complex z)
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
return (CMPLX(cosh(x), x * y));
sincos(y, &s, &c);
if (ix < 0x40360000) /* |x| < 22: normal case */
return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)));
return (CMPLX(cosh(x) * c, sinh(x) * s));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
h = exp(fabs(x)) * 0.5;
return (CMPLX(h * cos(y), copysign(h, x) * sin(y)));
h = exp(fabs(x)) / 2;
return (CMPLX(h * c, copysign(h, x) * s));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@ ccosh(double complex z)
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
return (CMPLX(h * h * cos(y), h * sin(y)));
return (CMPLX(h * h * c, h * s));
}
}
@@ -129,7 +131,9 @@ ccosh(double complex z)
if (ix == 0x7ff00000 && lx == 0) {
if (iy >= 0x7ff00000)
return (CMPLX(INFINITY, x * (y - y)));
return (CMPLX(INFINITY * cos(y), x * sin(y)));
sincos(y, &s, &c);
return (CMPLX(INFINITY * c, x * s));
}
/*
@@ -154,3 +158,8 @@ ccos(double complex z)
/* ccos(z) = ccosh(I * z) */
return (ccosh(CMPLX(-cimag(z), creal(z))));
}
#if (LDBL_MANT_DIG == 53)
__weak_reference(ccosh, ccoshl);
__weak_reference(ccos, ccosl);
#endif
+11 -7
View File
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
* Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ static const float huge = 0x1p127;
float complex
ccoshf(float complex z)
{
float x, y, h;
float c, h, s, x, y;
int32_t hx, hy, ix, iy;
x = crealf(z);
@@ -55,14 +55,16 @@ ccoshf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
return (CMPLXF(coshf(x), x * y));
sincosf(y, &s, &c);
if (ix < 0x41100000) /* |x| < 9: normal case */
return (CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
return (CMPLXF(coshf(x) * c, sinhf(x) * s));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
h = expf(fabsf(x)) * 0.5F;
return (CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)));
h = expf(fabsf(x)) / 2;
return (CMPLXF(h * c, copysignf(h, x) * s));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@ ccoshf(float complex z)
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
return (CMPLXF(h * h * cosf(y), h * sinf(y)));
return (CMPLXF(h * h * c, h * s));
}
}
@@ -86,7 +88,9 @@ ccoshf(float complex z)
if (ix == 0x7f800000) {
if (iy >= 0x7f800000)
return (CMPLXF(INFINITY, x * (y - y)));
return (CMPLXF(INFINITY * cosf(y), x * sinf(y)));
sincosf(y, &s, &c);
return (CMPLXF(INFINITY * c, x * s));
}
return (CMPLXF(((long double)x * x) * (y - y),
+16 -7
View File
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
* Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static const double huge = 0x1p1023;
double complex
csinh(double complex z)
{
double x, y, h;
double c, h, s, x, y;
int32_t hx, hy, ix, iy, lx, ly;
x = creal(z);
@@ -64,14 +64,16 @@ csinh(double complex z)
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
return (CMPLX(sinh(x), y));
sincos(y, &s, &c);
if (ix < 0x40360000) /* |x| < 22: normal case */
return (CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)));
return (CMPLX(sinh(x) * c, cosh(x) * s));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
h = exp(fabs(x)) * 0.5;
return (CMPLX(copysign(h, x) * cos(y), h * sin(y)));
h = exp(fabs(x)) / 2;
return (CMPLX(copysign(h, x) * c, h * s));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@ csinh(double complex z)
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
return (CMPLX(h * cos(y), h * h * sin(y)));
return (CMPLX(h * c, h * h * s));
}
}
@@ -128,7 +130,9 @@ csinh(double complex z)
if (ix == 0x7ff00000 && lx == 0) {
if (iy >= 0x7ff00000)
return (CMPLX(x, y - y));
return (CMPLX(x * cos(y), INFINITY * sin(y)));
sincos(y, &s, &c);
return (CMPLX(x * c, INFINITY * s));
}
/*
@@ -154,3 +158,8 @@ csin(double complex z)
z = csinh(CMPLX(cimag(z), creal(z)));
return (CMPLX(cimag(z), creal(z)));
}
#if (LDBL_MANT_DIG == 53)
__weak_reference(csinh, csinhl);
__weak_reference(csin, csinl);
#endif
+11 -7
View File
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
* Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ static const float huge = 0x1p127;
float complex
csinhf(float complex z)
{
float x, y, h;
float c, h, s, x, y;
int32_t hx, hy, ix, iy;
x = crealf(z);
@@ -55,14 +55,16 @@ csinhf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
return (CMPLXF(sinhf(x), y));
sincosf(y, &s, &c);
if (ix < 0x41100000) /* |x| < 9: normal case */
return (CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
return (CMPLXF(sinhf(x) * c, coshf(x) * s));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
h = expf(fabsf(x)) * 0.5F;
return (CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)));
h = expf(fabsf(x)) / 2;
return (CMPLXF(copysignf(h, x) * c, h * s));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@ csinhf(float complex z)
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
return (CMPLXF(h * cosf(y), h * h * sinf(y)));
return (CMPLXF(h * c, h * h * s));
}
}
@@ -86,7 +88,9 @@ csinhf(float complex z)
if (ix == 0x7f800000) {
if (iy >= 0x7f800000)
return (CMPLXF(x, y - y));
return (CMPLXF(x * cosf(y), INFINITY * sinf(y)));
sincosf(y, &s, &c);
return (CMPLXF(x * c, INFINITY * s));
}
return (CMPLXF(((long double)x + x) * (y - y),