abs(n) is as much arbitrary as the number of digits, i.e. roughly log10(abs(n) for integers...
This still does not work properly for non-integers, or large integers whose integral precision is lost by the value stored in exponential format with an aribtrary fixed number of digits.
Also I agree that length == 0 is valid to represent an empty set, but it's still not a valid Lua sequence number.
As well "#t" in Lua is not the total number of items in a table, but only the length of one of its extracted sequences.(which are not unique or could be empty if the table has holes for some sequence numbers. Meaning efefctively that "#t" or ipairs(t) is unreliable in Lua for tables, and works only for some of them that are valid sequences. And even if it's a valid sequence, there may still be more items in the table (whose keys are not integers or are integers <= 0 and thus implicitly excluded from sequences).
But your initial comment allowed the value 0 in keys of the input table, which was incorrect
Because it only allows 0 on valid output for the "length" of some unpredicatable sequence (including an empty sequence) extracted from the table,. If #t == 0, it does not mean that table t is empty..
In summary: saying a table's length == 0 is NOT equivalent to saying that the same table is empty. That's a good reson why the "#" operator and the ipairs() iterator in Lua are unrelaible, unpredictable, you should not create any generic algorigthm assuming it, or you'll need to check the result of pairs(t) to see if it returns at least one (key,value) pair or nil.