[PATCH 1/2] Avoid implicit floating point conversions [v2]
Corinna Vinschen
vinschen@redhat.com
Mon Aug 24 09:58:21 GMT 2020
On Aug 20 17:35, Keith Packard via Newlib wrote:
> These were found with clang -Wdouble-promotion and show places where
> floating point values were being implicitly converted between
> representations. These conversions can result in unexpected use of
> double precision arithmetic. Those which are intentional all have an
> explicit cast added.
> [...]
> diff --git a/newlib/libm/common/exp.c b/newlib/libm/common/exp.c
> index 12c08c992..f3e95c6f5 100644
> --- a/newlib/libm/common/exp.c
> +++ b/newlib/libm/common/exp.c
> @@ -114,9 +114,9 @@ exp (double x)
> return WANT_ROUNDING ? 1.0 + x : 1.0;
> if (abstop >= top12 (1024.0))
> {
> - if (asuint64 (x) == asuint64 (-INFINITY))
> + if (asuint64 (x) == asuint64 ((double) -INFINITY))
> return 0.0;
> - if (abstop >= top12 (INFINITY))
> + if (abstop >= top12 ((double) INFINITY))
Not taking implicit compiler optimisations into account, wouldn't it
make more sense to avoid the conversion altogether, using
__builtin_inf() in these places?
Thanks,
Corinna
More information about the Newlib
mailing list