lua-users home
lua-l archive

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

INT_MAX is perfectly acceptable, as far as I know.

Remember though, that any integer can be expressed perfectly fine in a double.
Although admittedly if you were calculating the number of repetitions using
some kind of recurring fraction, you may run in to issues. Fortunately these
issues would just be an error thrown, where as other parts of Lua would suffer
more (consider table accesses where sometimes you use an integer, other times
one bit off a perfect integer).

You are right though, that although it shouldn't surprise users that str.rep won't return a string
that can't possibly fit in the machines memory (on an x86, at least), silently failing is not
a brilliant solution.

If you really want to make the function bulletproof though, write it like this:
if (!((lua_Number) INT_MAX >= n)) {
  // raise error

(Welcome to the NaN, please enjoy your stay.)