lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hisham wrote:
> Random suggestion: how about a single function math.type() that
> returns the number subtype, "float" or "integer"?
> 
> At the risk of over-engineering, it also occurs to me that some
> libraries may want to know whether they're running with 32 or 64 bit
> ints or floats. This function could return that info as well, perhaps
> as a second return value.

That's a good idea, and it could also be merged with debug.numbits (which
doesn't seem to be a debug function):

math.type = function (x)
  if type(x) ~= "number" then return nil end
  local f = math.isfloat(x) and "f" or "i"
  return f, debug.numbits(f)
end

Another idea is to have an extended type function that returns this extra
information if the argument is a number:

local old_type = type
type = function (x)
  local t = old_type(x)
  if t ~= "number" then return t end
  local f = math.isfloat(x) and "f" or "i"
  return t, f, debug.numbits(f)
end

Cheers,
Luis

-- 
Computers are useless. They can only give you answers.
                -- Pablo Picasso

-- 
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'