Signed NaN

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Signed NaN

TonyMc
Hi,

I tried putting 0/0 into the Lua 5.4.0 interpreter and got a value of
-nan.  I am just wondering why the negative sign.  I know that the value
is mathematically undefined, but I sort of expected nan.

Best, Tony
Reply | Threaded
Open this post in threaded view
|

Re: Signed NaN

Luiz Henrique de Figueiredo
> I tried putting 0/0 into the Lua 5.4.0 interpreter and got a value of
> -nan.  I am just wondering why the negative sign.

Indeed, this happens in http://www.lua.org/demo.html , which runs in a
Linux box.
It does not happen in macOS. Thanks for the report.
Reply | Threaded
Open this post in threaded view
|

Re: Signed NaN

Roberto Ierusalimschy
In reply to this post by TonyMc
> I tried putting 0/0 into the Lua 5.4.0 interpreter and got a value of -nan.
> I am just wondering why the negative sign.  I know that the value is
> mathematically undefined, but I sort of expected nan.

This is something from the hardware. If you do that in C, which
generates the obvious machine code, it results in -nan too.

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: Signed NaN

Egor Skriptunoff-2
On Tue, Jul 14, 2020 at 3:51 PM Roberto Ierusalimschy wrote:
This is something from the hardware. If you do that in C, which
generates the obvious machine code, it results in -nan too.



C runtime library may mask the difference between HW results when converting nan to string:

Lua on Linux
> math.log(-1)
nan
> math.sqrt(-1)
-nan
> string.pack("d",math.log(-1)):byte(1,-1)
0   0   0   0   0   0   248   127
> string.pack("d",math.sqrt(-1)):byte(1,-1)
0   0   0   0   0   0   248   255
 

Lua on Windows (MinGW)
> math.log(-1)
nan
> math.sqrt(-1)
nan
> string.pack("d",math.log(-1)):byte(1,-1)
0   0   0   0   0   0   248   127
> string.pack("d",math.sqrt(-1)):byte(1,-1)
0   0   0   0   0   0   248   255