aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lvm.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lvm.c b/lvm.c
index fd74bff5..5e3c2ca0 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.350 2018/03/07 15:55:38 roberto Exp roberto $ 2** $Id: lvm.c,v 2.351 2018/03/16 14:21:20 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,24 +50,28 @@
50 50
51 51
52/* 52/*
53** 'l_intfitsf' checks whether a given integer can be converted to a 53** 'l_intfitsf' checks whether a given integer is in the range that
54** float without rounding. Used in comparisons. 54** can be converted to a float without rounding. Used in comparisons.
55*/ 55*/
56
56/* number of bits in the mantissa of a float */ 57/* number of bits in the mantissa of a float */
57#define NBM (l_mathlim(MANT_DIG)) 58#define NBM (l_mathlim(MANT_DIG))
58 59
59/* 60/*
60** Check whether some integers may not fit in a float, that is, whether 61** Check whether some integers may not fit in a float, testing whether
61** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger). 62** (maxinteger >> NBM) > 0. (That implies (1 << NBM) <= maxinteger.)
62** (The shifts are done in parts to avoid shifting by more than the size 63** (The shifts are done in parts, to avoid shifting by more than the size
63** of an integer. In a worst case, NBM == 113 for long double and 64** of an integer. In a worst case, NBM == 113 for long double and
64** sizeof(integer) == 32.) 65** sizeof(long) == 32.)
65*/ 66*/
66#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \ 67#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
67 >> (NBM - (3 * (NBM / 4)))) > 0 68 >> (NBM - (3 * (NBM / 4)))) > 0
68 69
69#define l_intfitsf(i) \ 70/* limit for integers that fit in a float */
70 (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM)) 71#define MAXINTFITSF ((lua_Unsigned)1 << NBM)
72
73/* check whether 'i' is in the interval [-MAXINTFITSF, MAXINTFITSF] */
74#define l_intfitsf(i) ((MAXINTFITSF + l_castS2U(i)) <= (2 * MAXINTFITSF))
71 75
72#else /* all integers fit in a float precisely */ 76#else /* all integers fit in a float precisely */
73 77