lua-users home
lua-l archive

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


On Tue, May 7, 2019 at 10:01 AM Andrew Starks <andrew@starksfam.org> wrote:

On 5/7/19, 4:55 AM, "lua-l-bounces@lists.lua.org on behalf of Dirk Laurie" <lua-l-bounces@lists.lua.org on behalf of dirk.laurie@gmail.com> wrote:

    Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
    > #-5
    stdin:1: attempt to get length of a number value
    stack traceback:
        stdin:1: in main chunk
        [C]: in ?
    > debug.setmetatable(0,{__len=math.abs})
    0
    > #-5
    5

 ----------

I like to give your crazy ideas at least a few brain cycles before I check out, but I'm wondering where you're going with this. I don't think I know enough math, but do math people have opinions about how long a number is, before they take mushrooms?

There are multiple, contradictory interpretations of "how long a number is". They all boil down to "how many digits?" but there are conflicting ways of answering that question.

How many digits are in 1? How many digits are in 1.00? How many digits are in 1e20? How many digits are in 0.001?

Are we counting decimal digits? Binary digits? Bytes? Is there a difference between the length of a float and the length of an int?

In the end the only answer that would be consistent would be to always return 8.

/s/ Adam