diff mbox series

[uclibc-ng-devel,v2] uclibc: Fix double promotion warning

Message ID 20240705143105.10071-2-marcus.haehnel@kernkonzept.com
State Superseded
Headers show
Series [uclibc-ng-devel,v2] uclibc: Fix double promotion warning | expand

Commit Message

Marcus Haehnel July 5, 2024, 2:29 p.m. UTC
Add casts where necessary to convince clang that the promotion of float
to double is intentional.

Signed-off-by: Sven Linker <sven.linker@kernkonzept.com>
---
v2: Missed some changed files in the first version.


 libc/stdio/_fpmaxtostr.c |  4 ++--
 libc/stdlib/_strtod.c    | 10 +++++-----
 libm/cexp.c              |  6 +++---
 libm/float_wrappers.c    |  2 +-
 libm/nan.c               |  4 ++--
 libm/w_cabs.c            |  2 +-
 6 files changed, 14 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libc/stdio/_fpmaxtostr.c b/libc/stdio/_fpmaxtostr.c
index b06b25aa0..1f268fdaa 100644
--- a/libc/stdio/_fpmaxtostr.c
+++ b/libc/stdio/_fpmaxtostr.c
@@ -318,8 +318,8 @@  ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
 
 #else  /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
 
-#define lower_bnd    1e8
-#define upper_bnd    1e9
+#define lower_bnd    (__fpmax_t)1e8
+#define upper_bnd    (__fpmax_t)1e9
 #define power_table  exp10_table
 #define dpb          DIGITS_PER_BLOCK
 #define base         10
diff --git a/libc/stdlib/_strtod.c b/libc/stdlib/_strtod.c
index c4c79e511..483551e64 100644
--- a/libc/stdlib/_strtod.c
+++ b/libc/stdlib/_strtod.c
@@ -256,7 +256,7 @@  __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp
 	}
 #endif
 
-	number = 0.;
+	number = (__fpmax_t)0;
 #ifdef _STRTOD_NEED_NUM_DIGITS
 	num_digits = -1;
 #endif
@@ -339,7 +339,7 @@  __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp
 				while ((pos[j] | 0x20) == nan_inf_str[i+1+j]) {
 					++j;
 					if (!nan_inf_str[i+1+j]) {
-						number = i / 0.;
+						number = i / (__fpmax_t)0.;
 						if (negative) {	/* Correct for sign. */
 							number = -number;
 						}
@@ -414,7 +414,7 @@  __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp
 	}
 
 #ifdef _STRTOD_ZERO_CHECK
-	if (number == 0.) {
+	if (number == (__fpmax_t)0.) {
 		goto DONE;
 	}
 #endif
@@ -515,7 +515,7 @@  float __XL_NPP(strtof)(const Wchar *str, Wchar **endptr   __LOCALE_PARAM )
 	x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
 	y = (float) x;
 
-	__fp_range_check(y, x);
+	__fp_range_check((__fpmax_t)y, x);
 
 	return y;
 #endif
@@ -549,7 +549,7 @@  double __XL_NPP(strtod)(const Wchar *__restrict str,
 	x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
 	y = (double) x;
 
-	__fp_range_check(y, x);
+	__fp_range_check((__fpmax_t)y, x);
 
 	return y;
 #endif
diff --git a/libm/cexp.c b/libm/cexp.c
index 87512b7c5..a08d12d4e 100644
--- a/libm/cexp.c
+++ b/libm/cexp.c
@@ -38,10 +38,10 @@  libm_hidden_proto(cexpf)
 __complex__ float cexpf(__complex__ float z)
 {
 	__complex__ float ret;
-	double r_exponent = exp(__real__ z);
+	double r_exponent = exp((double)__real__ z);
 
-	__real__ ret = r_exponent * cosf(__imag__ z);
-	__imag__ ret = r_exponent * sinf(__imag__ z);
+	__real__ ret = r_exponent * (double) cosf(__imag__ z);
+	__imag__ ret = r_exponent * (double) sinf(__imag__ z);
 
 	return ret;
 }
diff --git a/libm/float_wrappers.c b/libm/float_wrappers.c
index 948f6bc14..35887dde2 100644
--- a/libm/float_wrappers.c
+++ b/libm/float_wrappers.c
@@ -230,7 +230,7 @@  long_WRAPPER1(lround)
 float modff (float x, float *iptr)
 {
 	double y, result;
-	result = modf( x, &y );
+	result = modf( (double)x, &y );
 	*iptr = (float)y;
 	return (float) result;
 }
diff --git a/libm/nan.c b/libm/nan.c
index 454734b6f..9c2cd6e90 100644
--- a/libm/nan.c
+++ b/libm/nan.c
@@ -28,7 +28,7 @@  double nan (const char *tagp)
 		sprintf (buf, "NAN(%s)", tagp);
 		return strtod (buf, NULL);
 	}
-	return NAN;
+	return (double)NAN;
 }
 libm_hidden_def(nan)
 
@@ -53,7 +53,7 @@  long double nanl (const char *tagp)
 		sprintf (buf, "NAN(%s)", tagp);
 		return strtold (buf, NULL);
 	}
-	return NAN;
+	return (long double)NAN;
 }
 libm_hidden_def(nanl)
 #endif
diff --git a/libm/w_cabs.c b/libm/w_cabs.c
index b2592484c..546b6affa 100644
--- a/libm/w_cabs.c
+++ b/libm/w_cabs.c
@@ -17,7 +17,7 @@  libm_hidden_def(cabs)
 libm_hidden_proto(cabsf)
 float cabsf(float _Complex z)
 {
-	return (float) hypot(__real__ z, __imag__ z);
+	return (float) hypot((double)__real__ z, (double)__imag__ z);
 }
 libm_hidden_def(cabsf)