--****************************************************************************** --* * --* File: IntegerDomain.lua Revision: 1.0 * --* * --* Purpose: determines the range of integer values Lua is able to repre- * --* sent exactly(!) * --* * --* Creation: 14.11.2004 Last Modification: 14.11.2004 * --* * --* Environment: Lua 5.0, LuaJava 1.0b3, Java 1.4.2 * --* * --* Author: Andreas Rozek Phone: ++49 (7031) 222305 * --* Bunsenstraße 80/1 Fax: - * --* D-71032 Böblingen EMail: Info@Andreas-Rozek.De * --* Germany * --* * --* URL: http://www.Andreas-Rozek.de/ * --* * --* Copyright: the software is published under the "GNU Lesser General Pub- * --* lic License" (see "http://www.fsf.org/copyleft/lesser.html" * --* for additional information) * --* * --* Comments: this script was originally written using Lua 4.0 and then * --* converted to Lua 5.0 * --* * --****************************************************************************** println(); println("IntegerDomain - what is the largest supported integer number?"); println(); local Step = 2; while (true) do local nextStep = Step*2; if (math.floor(nextStep) == nextStep) and (nextStep-1 ~= nextStep) then Step = nextStep; else break; end; end; local Limit,Step = Step,Step/2; while (Step > 0) do local nextLimit = Limit+Step; if (math.floor(nextLimit) == nextLimit) and (nextLimit-1 ~= nextLimit) then Limit = nextLimit; end; Step = math.floor(Step/2); end; --local printableLimit = string.format("%d", Limit); -- fails under Lua! local printableLimit = string.format("%.16e", Limit); println("supported integer range is: -"..printableLimit.."...+"..printableLimit);