summaryrefslogtreecommitdiff
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-github-6b01b6cf6a1631f7ca2ce527a5c355517095c209.tar.gz
'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 @@
/*
-** $Id: lmathlib.c,v 1.123 2018/03/09 19:23:39 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.124 2018/03/11 14:48:09 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -321,7 +321,7 @@ typedef struct I {
** basic operations on 'I' values
*/
-static I pack (int h, int l) {
+static I pack (lu_int32 h, lu_int32 l) {
I result;
result.h = h;
result.l = l;
@@ -368,25 +368,27 @@ static I xorshift128plus (I *state) {
** Converts an 'I' into a float.
*/
+/* an unsigned 1 with proper type */
+#define UONE ((lu_int32)1)
+
#if FIGS <= 32
-/* do not need bits from higher half */
-#define maskHF 0
-#define maskLOW (~(~1U << (FIGS - 1))) /* use FIG bits */
-#define shiftFIG (l_mathop(0.5) / (1U << (FIGS - 1))) /* 2^(-FIG) */
+#define maskHF 0 /* do not need bits from higher half */
+#define maskLOW (~(~UONE << (FIGS - 1))) /* use FIG bits */
+#define shiftFIG (l_mathop(0.5) / (UONE << (FIGS - 1))) /* 2^(-FIG) */
#else /* 32 < FIGS <= 64 */
/* must take care to not shift stuff by more than 31 slots */
/* use FIG - 32 bits from higher half */
-#define maskHF (~(~1U << (FIGS - 33)))
+#define maskHF (~(~UONE << (FIGS - 33)))
/* use all bits from lower half */
-#define maskLOW (~0)
+#define maskLOW (~(lu_int32)0)
/* 2^(-FIG) == (1 / 2^33) / 2^(FIG-33) */
-#define shiftFIG ((lua_Number)(1.0 / 8589934592.0) / (1U << (FIGS - 33)))
+#define shiftFIG ((lua_Number)(1.0 / 8589934592.0) / (UONE << (FIGS - 33)))
#endif
@@ -403,7 +405,8 @@ static lua_Unsigned I2UInt (I x) {
}
static I Int2I (lua_Integer n) {
- return pack(n, n >> 31 >> 1);
+ lua_Unsigned un = n;
+ return pack((lu_int32)un, (lu_int32)(un >> 31 >> 1));
}
#endif /* } */