Mesa (master): util: Silent potential loss of precision warnings.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sat Jan 2 00:06:04 UTC 2010


Module: Mesa
Branch: master
Commit: c852e960ccb5d2727ccaaf2829e89596a6be3128
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c852e960ccb5d2727ccaaf2829e89596a6be3128

Author: José Fonseca <jfonseca at vmware.com>
Date:   Fri Jan  1 19:39:09 2010 +0000

util: Silent potential loss of precision warnings.

Also ensure multiplication doesn't happen for negative numbers.

---

 src/gallium/auxiliary/util/u_math.h |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 81aeb83..b2969a2 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -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));
 }
 
 




More information about the mesa-commit mailing list