util: Silent potential loss of precision warnings.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 1 Jan 2010 19:39:09 +0000 (19:39 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 2 Jan 2010 00:01:42 +0000 (00:01 +0000)
Also ensure multiplication doesn't happen for negative numbers.

src/gallium/auxiliary/util/u_math.h

index 81aeb83cbb5f149951492ce0f9cdc27ce3b8f200..b2969a210a7878f0daed5df6d715981139e2dc3d 100644 (file)
@@ -585,13 +585,12 @@ do {                                     \
 
 static INLINE uint32_t util_unsigned_fixed(float value, unsigned frac_bits)
 {
-   value *= (1<<frac_bits);
-   return value < 0 ? 0 : value;
+   return value < 0 ? 0 : (uint32_t)(value * (1<<frac_bits));
 }
 
 static INLINE int32_t util_signed_fixed(float value, unsigned frac_bits)
 {
-   return value * (1<<frac_bits);
+   return (int32_t)(value * (1<<frac_bits));
 }