[PATCH] various fixes detected with -Wdouble-promotion
Paul Zimmermann
Paul.Zimmermann@inria.fr
Sat Oct 11 07:16:26 GMT 2025
I tried also to fix issues in the test files (make check) but for some generic files
with "FLOAT" I did not know how to fix them without #pragma GCC diagnostic ignore.
In the end I thus did not touch the test files, and did "make check" without
-Wdouble-promotion. A separate commit might fix the test files if needed.
If this patch is accepted, it would be nice to add -Wdouble-promotion to the CI
tests, so that new patches are tested automatically.
---
math/w_jnf_compat.c | 2 +-
math/w_log2f_compat.c | 2 +-
math/w_tgammaf_compat.c | 2 +-
sysdeps/ieee754/dbl-64/e_lgamma_r.c | 2 +-
sysdeps/ieee754/dbl-64/s_fmaf.c | 2 +-
sysdeps/ieee754/flt-32/e_acosf.c | 4 ++--
sysdeps/ieee754/flt-32/e_atan2f.c | 6 +++---
sysdeps/ieee754/flt-32/e_coshf.c | 2 +-
sysdeps/ieee754/flt-32/e_exp10f.c | 2 +-
sysdeps/ieee754/flt-32/e_j0f.c | 6 +++---
sysdeps/ieee754/flt-32/e_j1f.c | 8 ++++----
sysdeps/ieee754/flt-32/e_jnf.c | 6 ++++--
sysdeps/ieee754/flt-32/e_lgammaf_r.c | 10 +++++-----
sysdeps/ieee754/flt-32/e_powf.c | 2 +-
sysdeps/ieee754/flt-32/e_remainderf.c | 4 ++--
sysdeps/ieee754/flt-32/e_sinhf.c | 2 +-
sysdeps/ieee754/flt-32/s_asinpif.c | 2 +-
sysdeps/ieee754/flt-32/s_atanpif.c | 4 ++--
sysdeps/ieee754/flt-32/s_erfcf.c | 2 +-
sysdeps/ieee754/flt-32/s_log10p1f.c | 2 +-
sysdeps/ieee754/flt-32/s_log1pf.c | 12 ++++++------
sysdeps/ieee754/flt-32/s_remquof.c | 2 +-
22 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/math/w_jnf_compat.c b/math/w_jnf_compat.c
index 8f465cee6e..4732d96bd5 100644
--- a/math/w_jnf_compat.c
+++ b/math/w_jnf_compat.c
@@ -52,7 +52,7 @@ __ynf (int n, float x)
feraiseexcept (FE_INVALID);
return __kernel_standard_f (n, x, 113);
}
- else if (x == 0.0)
+ else if (x == 0.0f)
{
/* d = -one/(x-x) */
feraiseexcept (FE_DIVBYZERO);
diff --git a/math/w_log2f_compat.c b/math/w_log2f_compat.c
index f26a97531d..e6a4658aa7 100644
--- a/math/w_log2f_compat.c
+++ b/math/w_log2f_compat.c
@@ -29,7 +29,7 @@ __log2f_compat (float x)
{
if (__builtin_expect (islessequal (x, 0.0f), 0) && _LIB_VERSION != _IEEE_)
{
- if (x == 0.0)
+ if (x == 0.0f)
{
feraiseexcept (FE_DIVBYZERO);
return __kernel_standard_f (x, x, 148); /* log2(0) */
diff --git a/math/w_tgammaf_compat.c b/math/w_tgammaf_compat.c
index addbdb1109..253d0c8b66 100644
--- a/math/w_tgammaf_compat.c
+++ b/math/w_tgammaf_compat.c
@@ -26,7 +26,7 @@ __tgammaf(float x)
float y = __ieee754_gammaf_r(x, NULL);
if(__glibc_unlikely (!isfinite (y) || y == 0)
- && (isfinite (x) || (isinf (x) && x < 0.0))
+ && (isfinite (x) || (isinf (x) && x < 0.0f))
&& _LIB_VERSION != _IEEE_) {
if (x == (float)0.0)
/* tgammaf pole */
diff --git a/sysdeps/ieee754/dbl-64/e_lgamma_r.c b/sysdeps/ieee754/dbl-64/e_lgamma_r.c
index 72c68b6682..62f6482e2b 100644
--- a/sysdeps/ieee754/dbl-64/e_lgamma_r.c
+++ b/sysdeps/ieee754/dbl-64/e_lgamma_r.c
@@ -231,7 +231,7 @@ __ieee754_lgamma_r(double x, int *signgamp)
if (x < -2.0 && x > -28.0)
return __lgamma_neg (x, signgamp);
t = sin_pi(x);
- if(t==zero) return one/fabsf(t); /* -integer */
+ if(t==zero) return one/fabs(t); /* -integer */
nadj = __ieee754_log(pi/fabs(t*x));
if(t<zero) *signgamp = -1;
x = -x;
diff --git a/sysdeps/ieee754/dbl-64/s_fmaf.c b/sysdeps/ieee754/dbl-64/s_fmaf.c
index 375bd13e0b..7bf9941dd8 100644
--- a/sysdeps/ieee754/dbl-64/s_fmaf.c
+++ b/sysdeps/ieee754/dbl-64/s_fmaf.c
@@ -45,7 +45,7 @@ __fmaf (float x, float y, float z)
/* Ensure correct sign of an exact zero result by performing the
addition in the original rounding mode in that case. */
- if (temp == -z)
+ if (temp == (double) -z)
return (float) temp + z;
union ieee754_double u;
diff --git a/sysdeps/ieee754/flt-32/e_acosf.c b/sysdeps/ieee754/flt-32/e_acosf.c
index 820e929864..929ad38342 100644
--- a/sysdeps/ieee754/flt-32/e_acosf.c
+++ b/sysdeps/ieee754/flt-32/e_acosf.c
@@ -112,9 +112,9 @@ __ieee754_acosf (float x)
if (ax < (0x7eu << 24))
{
if (t == 0x328885a3u)
- return 0x1.921fb6p+0f + 0x1p-25;
+ return 0x1.921fb6p+0f + 0x1p-25f;
if (t == 0x39826222u)
- return 0x1.920f6ap+0f + 0x1p-25;
+ return 0x1.920f6ap+0f + 0x1p-25f;
double x2 = xs * xs;
r = (pi2 - xs) - (xs * x2) * poly12 (x2, C0);
}
diff --git a/sysdeps/ieee754/flt-32/e_atan2f.c b/sysdeps/ieee754/flt-32/e_atan2f.c
index 82a0151293..1c72845c7c 100644
--- a/sysdeps/ieee754/flt-32/e_atan2f.c
+++ b/sysdeps/ieee754/flt-32/e_atan2f.c
@@ -73,7 +73,7 @@ cr_atan2f_tiny (float y, float x)
static const double c = -0x1.5555555555555p-2; /* -1/3 rounded to nearest */
double zz = z * z;
double cz = c * z;
- e = e / x + cz * zz;
+ e = e / dx + cz * zz;
uint64_t t = asuint64 (z);
if ((t & UINT64_C(0xfffffff)) == 0) /* boundary case */
{
@@ -139,7 +139,7 @@ __ieee754_atan2f (float y, float x)
if (ux >> 31)
return pi * sgn[uy >> 31];
else
- return 0.0f * sgn[uy >> 31];
+ return 0.0 * sgn[uy >> 31];
}
if (yinf)
return pi2 * sgn[uy >> 31];
@@ -155,7 +155,7 @@ __ieee754_atan2f (float y, float x)
return off[i];
}
if (!(ux >> 31))
- return 0.0f * sgn[uy >> 31];
+ return 0.0 * sgn[uy >> 31];
}
uint32_t gt = ay > ax;
uint32_t i = (uy >> 31) * 4 + (ux >> 31) * 2 + gt;
diff --git a/sysdeps/ieee754/flt-32/e_coshf.c b/sysdeps/ieee754/flt-32/e_coshf.c
index 382cd55cdf..c6c0392dab 100644
--- a/sysdeps/ieee754/flt-32/e_coshf.c
+++ b/sysdeps/ieee754/flt-32/e_coshf.c
@@ -77,7 +77,7 @@ __ieee754_coshf (float x)
double rm = sm * (te - h * to);
double r = rp + rm;
float ub = r;
- double lb = r - 1.45e-10 * r;
+ float lb = r - 1.45e-10 * r;
if (__glibc_unlikely (ub != lb))
{
const double iln2h = 0x1.7154765p+5;
diff --git a/sysdeps/ieee754/flt-32/e_exp10f.c b/sysdeps/ieee754/flt-32/e_exp10f.c
index 10e3b88523..aface56ff2 100644
--- a/sysdeps/ieee754/flt-32/e_exp10f.c
+++ b/sysdeps/ieee754/flt-32/e_exp10f.c
@@ -163,7 +163,7 @@ __exp10f (float x)
if (x < -0x2d.278d4p0f)
return __math_uflowf (0);
#if WANT_ERRNO_UFLOW
- if (x < -0x2c.da7cfp0)
+ if (x < -0x2c.da7cfp0f)
return __math_may_uflowf (0);
#endif
/* the smallest value such that 10^x >= 2^-126 (normal range)
diff --git a/sysdeps/ieee754/flt-32/e_j0f.c b/sysdeps/ieee754/flt-32/e_j0f.c
index 9ae91a9dcc..c800acd3cb 100644
--- a/sysdeps/ieee754/flt-32/e_j0f.c
+++ b/sysdeps/ieee754/flt-32/e_j0f.c
@@ -203,7 +203,7 @@ j0f_asympt (float x)
return 0xf.47039p-28f;
double y = 1.0 / (double) x;
double y2 = y * y;
- double beta0 = 1.0f + y2 * (-0x1p-4f + 0x1.a8p-4 * y2);
+ double beta0 = 1.0 + y2 * (-0x1p-4 + 0x1.a8p-4 * y2);
double alpha0 = y * (0x2p-4 - 0x1.0aaaaap-4 * y2);
double h;
int n;
@@ -484,7 +484,7 @@ y0f_asympt (float x)
return 0x1.a48974p-40f;
double y = 1.0 / (double) x;
double y2 = y * y;
- double beta0 = 1.0f + y2 * (-0x1p-4f + 0x1.a8p-4 * y2);
+ double beta0 = 1.0 + y2 * (-0x1p-4 + 0x1.a8p-4 * y2);
double alpha0 = y * (0x2p-4 - 0x1.0aaaaap-4 * y2);
double h;
int n;
@@ -529,7 +529,7 @@ y0f_near_root (float x, float z)
/* For degree 0 use a degree-5 polynomial, where the coefficients of
degree 4 and 5 are hard-coded. */
float p6 = (index > 0) ? p[6]
- : p[6] + y * (-0x3.a46c9p-4 + y * 0x3.735478p-4);
+ : p[6] + y * (-0x3.a46c9p-4f + y * 0x3.735478p-4f);
float res = p[3] + y * (p[4] + y * (p[5] + y * p6));
return res;
}
diff --git a/sysdeps/ieee754/flt-32/e_j1f.c b/sysdeps/ieee754/flt-32/e_j1f.c
index ade10402fd..4c35948060 100644
--- a/sysdeps/ieee754/flt-32/e_j1f.c
+++ b/sysdeps/ieee754/flt-32/e_j1f.c
@@ -207,7 +207,7 @@ j1f_asympt (float x)
}
double y = 1.0 / (double) x;
double y2 = y * y;
- double beta1 = 1.0f + y2 * (0x3p-4 - 0x3.18p-4 * y2);
+ double beta1 = 1.0 + y2 * (0x3p-4 - 0x3.18p-4 * y2);
double alpha1;
alpha1 = y * (-0x6p-4 + y2 * (0x2.ap-4 - 0x5.ef33333333334p-4 * y2));
double h;
@@ -494,7 +494,7 @@ y1f_asympt (float x)
float cst = 0xc.c422ap-4; /* sqrt(2/pi) rounded to nearest */
double y = 1.0 / (double) x;
double y2 = y * y;
- double beta1 = 1.0f + y2 * (0x3p-4 - 0x3.18p-4 * y2);
+ double beta1 = 1.0 + y2 * (0x3p-4 - 0x3.18p-4 * y2);
double alpha1;
alpha1 = y * (-0x6p-4 + y2 * (0x2.ap-4 - 0x5.ef33333333334p-4 * y2));
double h;
@@ -538,9 +538,9 @@ y1f_near_root (float x, float z)
float xmid = p[1];
float y = x - xmid, p6;
if (index == 0)
- p6 = p[6] + y * (-0x1.28043p-8 + y * 0x2.50e83p-8);
+ p6 = p[6] + y * (-0x1.28043p-8f + y * 0x2.50e83p-8f);
else if (index == 1)
- p6 = p[6] + y * -0xf.ff6b8p-12;
+ p6 = p[6] + y * -0xf.ff6b8p-12f;
else
p6 = p[6];
return p[3] + y * (p[4] + y * (p[5] + y * p6));
diff --git a/sysdeps/ieee754/flt-32/e_jnf.c b/sysdeps/ieee754/flt-32/e_jnf.c
index ff0a9d7c63..9d3e0aaaa3 100644
--- a/sysdeps/ieee754/flt-32/e_jnf.c
+++ b/sysdeps/ieee754/flt-32/e_jnf.c
@@ -61,7 +61,8 @@ __ieee754_jnf(int n, float x)
b = __ieee754_j1f(x);
for(i=1;i<n;i++){
temp = b;
- b = b*((double)(i+i)/x) - a; /* avoid underflow */
+ /* the following computation should be done in double precision */
+ b = (double)b*((double)(i+i)/(double)x) - (double)a; /* avoid underflow */
a = temp;
}
} else {
@@ -219,7 +220,8 @@ __ieee754_ynf(int n, float x)
GET_FLOAT_WORD(ib,b);
for(i=1;i<n&&ib!=0xff800000;i++){
temp = b;
- b = ((double)(i+i)/x)*b - a;
+ /* the following computation should be done in double precision */
+ b = ((double)(i+i)/(double)x)*(double)b - (double)a;
GET_FLOAT_WORD(ib,b);
a = temp;
}
diff --git a/sysdeps/ieee754/flt-32/e_lgammaf_r.c b/sysdeps/ieee754/flt-32/e_lgammaf_r.c
index 75ec25fb9e..1439708d12 100644
--- a/sysdeps/ieee754/flt-32/e_lgammaf_r.c
+++ b/sysdeps/ieee754/flt-32/e_lgammaf_r.c
@@ -188,6 +188,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
*signgamp = 1 - ((((int) fx) & 1) << 1);
double z = ax, f;
+ double s = x;
if (__glibc_unlikely (ax < 0x1.52p-1f))
{
static const double rn[] =
@@ -205,7 +206,6 @@ __ieee754_lgammaf_r (float x, int *signgamp)
-0x1.7dd25af0b83d4p+0, -0x1.36bf1880125fcp+0,
-0x1.1379fc8023d9cp+0, -0x1.03712e41525d2p+0
};
- double s = x;
f = (c0 * s) * as_r8 (s, rn) / as_r8 (s, rd) - as_ln (z);
}
else
@@ -215,7 +215,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
if (__glibc_unlikely (x > 0x1.895f1cp+121f))
return math_narrow_eval (0x1p127f * 0x1p127f);
/* |x|>=2**23, must be -integer */
- if (__glibc_unlikely (x < 0.0f && ax > 0x1p+23))
+ if (__glibc_unlikely (x < 0.0f && ax > 0x1p+23f))
return ax / 0.0f;
double lz = as_ln (z);
f = (z - 0.5) * (lz - 1) + 0x1.acfe390c97d69p-2;
@@ -293,7 +293,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
{
if (__glibc_unlikely (t < 0x40301b93u && t > 0x402f95c2u))
{
- double h = (x + 0x1.5fb410a1bd901p+1)
+ double h = (s + 0x1.5fb410a1bd901p+1)
- 0x1.a19a96d2e6f85p-54;
double h2 = h * h;
double h4 = h2 * h2;
@@ -309,7 +309,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
}
else if (__glibc_unlikely (t > 0x401ceccbu && t < 0x401d95cau))
{
- double h = (x + 0x1.3a7fc9600f86cp+1)
+ double h = (s + 0x1.3a7fc9600f86cp+1)
+ 0x1.55f64f98af8dp-55;
double h2 = h * h;
double h4 = h2 * h2;
@@ -326,7 +326,7 @@ __ieee754_lgammaf_r (float x, int *signgamp)
}
else if (__glibc_unlikely (t > 0x40492009u && t < 0x404940efu))
{
- double h = (x + 0x1.9260dbc9e59afp+1)
+ double h = (s + 0x1.9260dbc9e59afp+1)
+ 0x1.f717cd335a7b3p-53;
double h2 = h * h;
double h4 = h2 * h2;
diff --git a/sysdeps/ieee754/flt-32/e_powf.c b/sysdeps/ieee754/flt-32/e_powf.c
index ae3af360db..06587140fb 100644
--- a/sysdeps/ieee754/flt-32/e_powf.c
+++ b/sysdeps/ieee754/flt-32/e_powf.c
@@ -203,7 +203,7 @@ __powf (float x, float y)
}
}
double_t logx = log2_inline (ix);
- double_t ylogx = y * logx; /* Note: cannot overflow, y is single prec. */
+ double_t ylogx = (double) y * logx; /* Note: cannot overflow, y is single prec. */
if (__glibc_unlikely ((asuint64 (ylogx) >> 47 & 0xffff)
>= asuint64 (126.0 * POWF_SCALE) >> 47))
{
diff --git a/sysdeps/ieee754/flt-32/e_remainderf.c b/sysdeps/ieee754/flt-32/e_remainderf.c
index d0f069fbd2..6e6d687263 100644
--- a/sysdeps/ieee754/flt-32/e_remainderf.c
+++ b/sysdeps/ieee754/flt-32/e_remainderf.c
@@ -46,7 +46,7 @@ __ieee754_remainderf(float x, float p)
x -= p;
/* Make sure x is not -0. This can occur only when x = p
and rounding direction is towards negative infinity. */
- else if (x == 0.0)
+ else if (x == 0.0f)
x = 0.0;
}
}
@@ -63,7 +63,7 @@ __ieee754_remainderf(float x, float p)
x -= p;
if (x >= p_half)
x -= p;
- else if (x == 0.0)
+ else if (x == 0.0f)
x = 0.0;
}
}
diff --git a/sysdeps/ieee754/flt-32/e_sinhf.c b/sysdeps/ieee754/flt-32/e_sinhf.c
index 6c8c1db404..5e812c35af 100644
--- a/sysdeps/ieee754/flt-32/e_sinhf.c
+++ b/sysdeps/ieee754/flt-32/e_sinhf.c
@@ -91,7 +91,7 @@ __ieee754_sinhf (float x)
double rm = sm * (te - h * to);
double r = rp - rm;
float ub = r;
- double lb = r - 1.52e-10 * r;
+ float lb = r - 1.52e-10 * r;
if (__glibc_unlikely (ub != lb))
{
const double iln2h = 0x1.7154765p+5;
diff --git a/sysdeps/ieee754/flt-32/s_asinpif.c b/sysdeps/ieee754/flt-32/s_asinpif.c
index f9e93533d4..cef6386446 100644
--- a/sysdeps/ieee754/flt-32/s_asinpif.c
+++ b/sysdeps/ieee754/flt-32/s_asinpif.c
@@ -65,7 +65,7 @@ __asinpif (float x)
c0 += c2 * z4;
c4 += c6 * z4;
c0 += c4 * (z4 * z4);
- if (__glibc_unlikely (ax != 0.0 && ax <= 0x1.921fb4p-126f))
+ if (__glibc_unlikely (ax != 0.0f && ax <= 0x1.921fb4p-126f))
__set_errno (ERANGE);
return z * c0;
}
diff --git a/sysdeps/ieee754/flt-32/s_atanpif.c b/sysdeps/ieee754/flt-32/s_atanpif.c
index 8d78163418..0a46a5bcd0 100644
--- a/sysdeps/ieee754/flt-32/s_atanpif.c
+++ b/sysdeps/ieee754/flt-32/s_atanpif.c
@@ -48,7 +48,7 @@ __atanpif (float x)
}
/* Warning: 0x1.45f306p-2f / x underflows for |x| >= 0x1.45f306p+124 */
if (fabsf (x) >= 0x1.45f306p+124f)
- return f - copysign (0x1p-26f, x);
+ return f - copysignf (0x1p-26f, x);
else
return f - 0x1.45f306p-2f / x;
}
@@ -63,7 +63,7 @@ __atanpif (float x)
__set_errno (ERANGE);
return rsx;
}
- return sx - (0x1.5555555555555p-2 * sx) * (x * x);
+ return sx - (0x1.5555555555555p-2 * sx) * (z * z);
}
uint32_t ax = t & (~0u >> 1);
if (__glibc_unlikely (ax == 0x3fa267ddu))
diff --git a/sysdeps/ieee754/flt-32/s_erfcf.c b/sysdeps/ieee754/flt-32/s_erfcf.c
index 955f129148..ee83604c41 100644
--- a/sysdeps/ieee754/flt-32/s_erfcf.c
+++ b/sysdeps/ieee754/flt-32/s_erfcf.c
@@ -131,7 +131,7 @@ __erfcf (float xf)
0x1.20dd750429b6dp+0, -0x1.812746b03610bp-2, 0x1.ce2f218831d2fp-4,
-0x1.b82c609607dcbp-6, 0x1.553af09b8008ep-8
};
- double f0 = xf
+ double f0 = (double) xf
* (c[0] + x2 * (c[1] + x2 * (c[2] + x2 * (c[3] + x2 * (c[4])))));
return 1.0 - f0;
}
diff --git a/sysdeps/ieee754/flt-32/s_log10p1f.c b/sysdeps/ieee754/flt-32/s_log10p1f.c
index 4e11d55d49..d9e1149201 100644
--- a/sysdeps/ieee754/flt-32/s_log10p1f.c
+++ b/sysdeps/ieee754/flt-32/s_log10p1f.c
@@ -155,7 +155,7 @@ __log10p1f (float x)
0x1.63c62378fa3dbp-3, 0x1.fca4139a42374p-4
};
float ret = z * ((c[0] + z2 * c[1]) + z4 * (c[2] + z2 * c[3]));
- if (x != 0.0f && ret == 0.0)
+ if (x != 0.0f && ret == 0.0f)
__set_errno (ERANGE);
return ret;
}
diff --git a/sysdeps/ieee754/flt-32/s_log1pf.c b/sysdeps/ieee754/flt-32/s_log1pf.c
index d1686e78aa..f03c60df34 100644
--- a/sysdeps/ieee754/flt-32/s_log1pf.c
+++ b/sysdeps/ieee754/flt-32/s_log1pf.c
@@ -154,21 +154,21 @@ __log1pf (float x)
double tr = rl + Lh;
if (__glibc_unlikely ((asuint64 (tr) & 0xfffffffll) == 0))
{
- if (x == -0x1.247ab0p-6)
+ if (x == -0x1.247ab0p-6f)
return -0x1.271f0ep-6f - 0x1p-31f;
- if (x == -0x1.3a415ep-5)
+ if (x == -0x1.3a415ep-5f)
return -0x1.407112p-5f + 0x1p-30f;
- if (x == 0x1.fb035ap-2)
+ if (x == 0x1.fb035ap-2f)
return 0x1.9bddc2p-2f + 0x1p-27f;
tr += 64 * (rl + (Lh - tr));
}
else if (rl + (Lh - tr) == 0.0)
{
- if (x == 0x1.b7fd86p-4)
+ if (x == 0x1.b7fd86p-4f)
return 0x1.a1ece2p-4f + 0x1p-29f;
- if (x == -0x1.3a415ep-5)
+ if (x == -0x1.3a415ep-5f)
return -0x1.407112p-5f + 0x1p-30f;
- if (x == 0x1.43c7e2p-6)
+ if (x == 0x1.43c7e2p-6f)
return 0x1.409f80p-6f + 0x1p-31f;
}
ub = tr;
diff --git a/sysdeps/ieee754/flt-32/s_remquof.c b/sysdeps/ieee754/flt-32/s_remquof.c
index f813da8c91..67d301b3e1 100644
--- a/sysdeps/ieee754/flt-32/s_remquof.c
+++ b/sysdeps/ieee754/flt-32/s_remquof.c
@@ -85,7 +85,7 @@ __remquof (float x, float y, int *quo)
}
else
{
- float y_half = 0.5 * y;
+ float y_half = 0.5f * y;
if (x > y_half)
{
x -= y;
--
2.51.0
More information about the Libc-alpha
mailing list