aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-12 09:39:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-03-12 09:39:03 -0300
commit6b01b6cf6a1631f7ca2ce527a5c355517095c209 (patch)
tree763750a279d5a40210bc5943440b088ebc718f4d /lmathlib.c
parente3388ebfad4a566c933b2b1562cfa9f40a8afc13 (diff)
downloadlua-6b01b6cf6a1631f7ca2ce527a5c355517095c209.tar.gz
lua-6b01b6cf6a1631f7ca2ce527a5c355517095c209.tar.bz2
lua-6b01b6cf6a1631f7ca2ce527a5c355517095c209.zip
'lu_int32' may not be 'int'
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/lmathlib.c b/lmathlib.c
index b60c661a..c5c3c541 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.123 2018/03/09 19:23:39 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.124 2018/03/11 14:48:09 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*/
@@ -321,7 +321,7 @@ typedef struct I {
321** basic operations on 'I' values 321** basic operations on 'I' values
322*/ 322*/
323 323
324static I pack (int h, int l) { 324static I pack (lu_int32 h, lu_int32 l) {
325 I result; 325 I result;
326 result.h = h; 326 result.h = h;
327 result.l = l; 327 result.l = l;
@@ -368,25 +368,27 @@ static I xorshift128plus (I *state) {
368** Converts an 'I' into a float. 368** Converts an 'I' into a float.
369*/ 369*/
370 370
371/* an unsigned 1 with proper type */
372#define UONE ((lu_int32)1)
373
371#if FIGS <= 32 374#if FIGS <= 32
372 375
373/* do not need bits from higher half */ 376#define maskHF 0 /* do not need bits from higher half */
374#define maskHF 0 377#define maskLOW (~(~UONE << (FIGS - 1))) /* use FIG bits */
375#define maskLOW (~(~1U << (FIGS - 1))) /* use FIG bits */ 378#define shiftFIG (l_mathop(0.5) / (UONE << (FIGS - 1))) /* 2^(-FIG) */
376#define shiftFIG (l_mathop(0.5) / (1U << (FIGS - 1))) /* 2^(-FIG) */
377 379
378#else /* 32 < FIGS <= 64 */ 380#else /* 32 < FIGS <= 64 */
379 381
380/* must take care to not shift stuff by more than 31 slots */ 382/* must take care to not shift stuff by more than 31 slots */
381 383
382/* use FIG - 32 bits from higher half */ 384/* use FIG - 32 bits from higher half */
383#define maskHF (~(~1U << (FIGS - 33))) 385#define maskHF (~(~UONE << (FIGS - 33)))
384 386
385/* use all bits from lower half */ 387/* use all bits from lower half */
386#define maskLOW (~0) 388#define maskLOW (~(lu_int32)0)
387 389
388/* 2^(-FIG) == (1 / 2^33) / 2^(FIG-33) */ 390/* 2^(-FIG) == (1 / 2^33) / 2^(FIG-33) */
389#define shiftFIG ((lua_Number)(1.0 / 8589934592.0) / (1U << (FIGS - 33))) 391#define shiftFIG ((lua_Number)(1.0 / 8589934592.0) / (UONE << (FIGS - 33)))
390 392
391#endif 393#endif
392 394
@@ -403,7 +405,8 @@ static lua_Unsigned I2UInt (I x) {
403} 405}
404 406
405static I Int2I (lua_Integer n) { 407static I Int2I (lua_Integer n) {
406 return pack(n, n >> 31 >> 1); 408 lua_Unsigned un = n;
409 return pack((lu_int32)un, (lu_int32)(un >> 31 >> 1));
407} 410}
408 411
409#endif /* } */ 412#endif /* } */