[ Impressum ]


www.Rozek.de > Lua
This page contains a few articles from my Lua[1] period, which should either remain accessible because of public references to them (such as the Lua logos), or are still interesting because of their functionality (such as the computation of the integer value range, which is also relevant for JavaScript in this form).

You will find this (and other) content on my page in the Lua-Users Wiki.

Lua Logo as a PNG Image

Initially, the Lua logo was only available as an EPS or BMP file - so I once just converted it into a PNG with alpha channel:

Integer Domain of Numbers in the Format IEEE 754

Similar to JavaScript, Lua also (usually) does not distinguish between integers and floating point numbers - in fact, numbers are always stored in the IEEE 754 double-precision format (using 64-bit). However, this is often not at all tragic, as the format is able to store integers in a fairly wide range without loss.

The following Lua function calculates the number range which may be used for integers (see also http://lua-users.org/wiki/IntegerDomain):

--**** should be compatible with 5.xx ****
function intlimit()
local floor = math.floor

--**** get highest power of 2 which Lua can still handle as integer ****
local step = 2
while true do
local nextstep = step*2
if (floor(nextstep) == nextstep) and (nextstep-1 ~= nextstep) then
step = nextstep

--**** now get the highest number which Lua can still handle as integer ****
local limit,step = step,step/2
while step > 0 do
local nextlimit = limit+step
if (floor(nextlimit) == nextlimit) and (nextlimit-1 ~= nextlimit) then
limit = nextlimit
step = floor(step/2)
return limit

This function can now be embedded and tested in a small program:

local limit = intlimit()

print("IntegerDomain - what is the largest supported integer number?")

--**** do not rely on Lua to print "limit" properly by itself! ****
--local printablelimit = string.format("%d", limit) -- fails under Lua!
local printablelimit = string.format("%.16e", limit)

print("supported integer range is: -" ..
printablelimit .. "...+" .. printablelimit)

The output of this program looks as follows:

IntegerDomain - what is the largest supported integer number?

supported integer range is: -9.0071992547409940e+15...+9.0071992547409940e+15

The usable range is thus -9007199254740994...+9007199254740994 (both included), which should be sufficient for most applications.


(Lua Team)
The Programming Language Lua
The given address is the primary starting point for any investigation about Lua: from here you are directed to Lua distributions, documentation, additional libraries or tools - and you may get in contact with other Lua users