lua-users home
lua-l archive

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


On Jan 2, 2008 8:16 AM, Reuben Thomas <rrt@sc3d.org> wrote:
> It would make it easier to write portable code for Lua if there were maxima
> and minima for the number types, say LUA_NUMBER_MAX, LUA_NUMBER_MIN &c. For
> a default configured system, one can of course use the limits for the
> default types, ptrdiff_t and double respectively, but that's not portable to
> systems using non-default types.
>
> --
> http://rrt.sc3d.org/
> memoir, n.  a lie that flatters the author's ego and the reader's intellect
>

The maximum value, as in highest possible exponent, or highest
possible integer mantissa? The two are noticably different. With 64
bit double-precision, the maximum number is 1.7976931348623157 x
10^308, however the 53 bit mantissa loses resolution about
9007199254740991.

A nice way to verify that second number would be this:

function maxluanumber()
  local x = 1
  while x < x +1 do
    x = x * 2
  end
  return x
end