Ever since we updated to clang 10, there have been compiler warnings in
libm about loss of precision when converting long and long long to
double.
/usr/src/lib/libm/src/s_lroundl.c:51:31: warning: implicit conversion from
'long' to 'double' c
hanges value from 9223372036854775807 to 9223372036854775808
[-Wimplicit-const-int-float-conver
sion]
static const type dtype_max = DTYPE_MAX + 0.5;
^~~~~~~~~ ~
/usr/src/lib/libm/src/s_lroundl.c:38:19: note: expanded from macro 'DTYPE_MAX'
#define DTYPE_MAX LONG_MAX
^~~~~~~~
/usr/include/sys/limits.h:63:19: note: expanded from macro 'LONG_MAX'
# define LONG_MAX 0x7fffffffffffffffL
^~~~~~~~~~~~~~~~~~~
1 warning generated.
And a second one for LLONG_MAX from s_llroundl.c.
The fix from FreeBSD silences both of them and looks correct to me.
https://github.com/freebsd/freebsd-src/commit/e593620997cc1db24295398117dffca5c2a204e0
Index: lib/libm/src/s_lroundl.c
===================================================================
RCS file: /cvs/src/lib/libm/src/s_lroundl.c,v
retrieving revision 1.3
diff -u -p -r1.3 s_lroundl.c
--- lib/libm/src/s_lroundl.c 15 Mar 2019 05:42:38 -0000 1.3
+++ lib/libm/src/s_lroundl.c 27 May 2021 10:43:20 -0000
@@ -47,9 +47,9 @@
* that everything is in range. At compile time, INRANGE(x) should reduce to
* two floating-point comparisons in the former case, or TRUE otherwise.
*/
-static const type dtype_min = DTYPE_MIN - 0.5;
-static const type dtype_max = DTYPE_MAX + 0.5;
-#define INRANGE(x) (dtype_max - DTYPE_MAX != 0.5 || \
+static const type dtype_min = (type)DTYPE_MIN - 0.5;
+static const type dtype_max = (type)DTYPE_MAX + 0.5;
+#define INRANGE(x) (dtype_max - (type)DTYPE_MAX != 0.5 || \
((x) > dtype_min && (x) < dtype_max))
dtype