lua-users home
lua-l archive

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

> You mean using strings with math.tointeger()?
> If that's the case, I think we should have math.tointeger()
> and math.tofloat(), and tonumber() should be smart.
> For backwards compatibility, too.

+1 for that. math.tointeger for integers and math.tofloat for floats/doubles (Maybe call it math.torational?)

math.tointeger should maybe allow a extra string argument for "undefined", "default" (=return nil, errmsg), "truncate" and "modulo" behaviour and math.torational should return INF/-INF when possible.
tonumber(x) should return math.tointeger(x, "default"), math.tointeger(x) or nil

By the way, math.tointeger (and math.torational) should really return nil, errmsg.