From 86710c1716bb3d5e4cfac782d63f4b724570ca4c Mon Sep 17 00:00:00 2001 From: Mark Cannon Date: Tue, 23 Aug 2011 11:39:57 -0700 Subject: [PATCH] fix compilation for MersenneTwister; generate 2^32 constant with pow(), so it doesn't depend on compiler semantics --- src/RageUtil.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index d4622ce9a3..43baf1756a 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -98,6 +98,9 @@ namespace { MersenneTwister g_LuaPRNG; + /* To map from [0..2^32-1] to [0..1), we divide by 2^32. */ + const double DIVISOR = pow( double(2), double(32) ); + static int Seed( lua_State *L ) { g_LuaPRNG.Reset( IArg(1) ); @@ -111,9 +114,7 @@ namespace /* [0..1) */ case 0: { - /* we get values in [0..(2^32-1)]; divide by 2^32. */ - /* XXX: get rid of long long to double conversion */ - double r = double(g_LuaPRNG()) / double(0x100000000llu); + double r = double(g_LuaPRNG()) / DIVISOR; lua_pushnumber( L, r ); return 1; }