• Subject: Re: Numeric key collision related bug in Lua 5.3
• From: Tim Hill <drtimhill@...>
• Date: Tue, 21 Apr 2015 13:42:06 -0700

 On Apr 21, 2015, at 1:35 PM, Tim Hill wrote:On Apr 21, 2015, at 1:23 PM, Liam Devine wrote:On 21/04/15 21:04, Andrew Starks wrote:It would add tremendously to my understanding if someone someone wouldmake up a story that includes a user in a real-world scenario hittingthis edge case. ...-AndrewCorrection to my earlier email a this does not just effect rawequal.a, b = math.maxinteger + 2.1, math.maxinteger + 3.5print(math.type(a), math.type(b))float floatreturn a == btrueThis is expected behavior. math.maxinteger is 2^63-1. An IEEE754 double-precision float has 53 bits for the mantissa. Since your integer has a magnitude of approx 2^63, only the most significant 53 bits are stored (along with an appropriate exponent) and the lower 10 bits are lost to rounding errors (again, as expected). So the smallest delta that will actually generate a different float value is approx 2^10, or 1024..mi = math.maxintegera, b = mi + 1024, mi + 2048print(a==b) -> false—Tim(Sorry, missed the “.0” in the two constants above, but you get my meaning I’m sure.)In fact, consider the following:c = 10.0e18d = cfor i = 1,10000 do c = c + 100.0 endprint(c == d)You can add 100.0 to c forever and it’s value will never change. Welcome to the world of limited precision floating point :)—Tim