From 18fd5c908197dec7ea7da5112a9f6a3858e67d03 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 1 Mar 2013 16:24:20 +0000 Subject: [PATCH] math: try to refactor rand() to bypass an X360 compiler bug. --- src/lol/math/rand.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lol/math/rand.h b/src/lol/math/rand.h index 3938904c..e60d0812 100644 --- a/src/lol/math/rand.h +++ b/src/lol/math/rand.h @@ -33,14 +33,29 @@ template static inline T rand(T a) return rand() % a; } -template<> -inline half rand(half a) { return a * std::rand() / RAND_MAX; } -template<> -inline float rand(float a) { return a * std::rand() / RAND_MAX; } -template<> -inline double rand(double a) { return a * std::rand() / RAND_MAX; } -template<> -inline ldouble rand(ldouble a) { return a * std::rand() / RAND_MAX; } +template<> inline half rand(half a) +{ + float f = (float)std::rand() / (float)RAND_MAX; + return (half)(a * f); +} + +template<> inline float rand(float a) +{ + float f = (float)std::rand() / (float)RAND_MAX; + return a * f; +} + +template<> inline double rand(double a) +{ + double f = (double)std::rand() / (double)RAND_MAX; + return a * f; +} + +template<> inline ldouble rand(ldouble a) +{ + ldouble f = (ldouble)std::rand() / (ldouble)RAND_MAX; + return a * f; +} /* Two-value random number generator -- no need for specialisation */ template static inline T rand(T a, T b)