From 04976d7f23da03e4bebbe50fd3548c8b4d7c26fc Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 22 Oct 2022 18:30:14 +0100 Subject: Floating point maths: Squash clang warning Implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion] --- include/libcss/fpmath.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/libcss/fpmath.h b/include/libcss/fpmath.h index bed5ee6..d7cac4d 100644 --- a/include/libcss/fpmath.h +++ b/include/libcss/fpmath.h @@ -99,10 +99,12 @@ css_float_to_fixed(const float a) { float xx = a * (float) (1 << CSS_RADIX_POINT); if (xx < INT_MIN) - xx = INT_MIN; + return INT_MIN; - if (xx > INT_MAX) - xx = INT_MAX; + /* Conversion from int to float changes value from + * 2147483647 to 2147483648, so we use >= instead of >. */ + if (xx >= (float)INT_MAX) + return INT_MAX; return (css_fixed) xx; } -- cgit v1.2.1