aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-11 11:48:09 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-11 11:48:09 -0300
commite3388ebfad4a566c933b2b1562cfa9f40a8afc13 (patch)
treee35ff74969885932b9d04c5e4f2557d20607b88a /lmathlib.c
parent9e3db70482e927e5992cccdb5a40424b33ad0a29 (diff)
downloadlua-e3388ebfad4a566c933b2b1562cfa9f40a8afc13.tar.gz
lua-e3388ebfad4a566c933b2b1562cfa9f40a8afc13.tar.bz2
lua-e3388ebfad4a566c933b2b1562cfa9f40a8afc13.zip
more explicit casts when converting an integer to a random float
(to ensure computations are done with all bits)
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 2b5fd46d..b60c661a 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.122 2018/03/09 15:05:13 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.123 2018/03/09 19:23:39 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -373,7 +373,7 @@ static I xorshift128plus (I *state) {
373/* do not need bits from higher half */ 373/* do not need bits from higher half */
374#define maskHF 0 374#define maskHF 0
375#define maskLOW (~(~1U << (FIGS - 1))) /* use FIG bits */ 375#define maskLOW (~(~1U << (FIGS - 1))) /* use FIG bits */
376#define shiftFIG (0.5 / (1U << (FIGS - 1))) /* 2^(-FIG) */ 376#define shiftFIG (l_mathop(0.5) / (1U << (FIGS - 1))) /* 2^(-FIG) */
377 377
378#else /* 32 < FIGS <= 64 */ 378#else /* 32 < FIGS <= 64 */
379 379
@@ -393,7 +393,9 @@ static I xorshift128plus (I *state) {
393#define twoto32 l_mathop(4294967296.0) /* 2^32 */ 393#define twoto32 l_mathop(4294967296.0) /* 2^32 */
394 394
395static lua_Number I2d (I x) { 395static lua_Number I2d (I x) {
396 return ((x.h & maskHF) * twoto32 + (x.l & maskLOW)) * shiftFIG; 396 lua_Number h = (lua_Number)(x.h & maskHF);
397 lua_Number l = (lua_Number)(x.l & maskLOW);
398 return (h * twoto32 + l) * shiftFIG;
397} 399}
398 400
399static lua_Unsigned I2UInt (I x) { 401static lua_Unsigned I2UInt (I x) {