[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua minus null (-0)
- From: David Kastrup <dak@...>
- Date: Thu, 09 Jun 2011 17:26:52 +0200
Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> writes:
>> #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)+0.0)
>
> That seems to work but can be confusing as well:
> z=0 a=z b=-z print(a,b,a==b,1/a,1/b)
> now prints
> 0 0 true inf -inf
> when it originally printed
> 0 -0 true inf -inf
>
Well, so what?
Either case we have a==b, and 1/a ~= 1/b. As long as a==b, the basic
surprise is f(a)~=f(b). f(x)=1/x yields such a surprise,
f(x)=tostring(x) does, f(x)=x+0 does not, and f(x)=tostring(x+0) does
not, either. I don't see how having -0 print differently when it
compares equal is of help.
It is not like
> z=1e-10 a=z b=z+1e-25 print(a,b,a==b,1/a,1/b)
1e-10 1e-10 false 10000000000 10000000000
> z=1e-10 a=z b=z+1e-24 print(a,b,a==b,1/a,1/b)
1e-10 1e-10 false 10000000000 9999999999.9999
are particularly surprising, either. Why do we want differing print
representations for values comparing as equal when we don't even have
differing print representations for some values comparing as unequal?
--
David Kastrup
- References:
- Re: Lua minus null (-0), Dirk Laurie
- Re: Lua minus null (-0), Henk Boom
- Re: Lua minus null (-0), Dirk Laurie
- Re: Lua minus null (-0), Everett L Williams II
- Re: Lua minus null (-0), Dirk Laurie
- Re: Lua minus null (-0), David Kastrup
- Re: Lua minus null (-0), Dirk Laurie
- Re: Lua minus null (-0), David Kastrup
- Re: Lua minus null (-0), Dirk Laurie
- Re: Lua minus null (-0), David Kastrup
- Re: Lua minus null (-0), Luiz Henrique de Figueiredo