Negative zero??

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
User avatar
dingo
Posts: 2
Joined: Thu Nov 17, 2005 5:51 am

Negative zero??

Post by dingo »

Hello.. First post here.
I noticed an odd bug in luaplayer while working on my complex number calculator. Someone must have surely noticed this, but I've tried searching and I've not found anything.
According to Luaplayer, -1*0 = -0..
Here's the code I've tested it with:

Code: Select all

zero = 0*-1
screen:fillRect(0,0,480,272,Color.new(0,0,0))
screen:print(200,100,tostring(zero),Color.new(255,255,255))
screen:print(200,110,tostring(zero == 0), Color.new(255,255,255))

screen:flip()

while true do
	screen.waitVblankStart()
end
it outputs this:
-0
true

which I guess means -0 has a different value to 0, but is still equal to it.

I'm using user-mode lua (for 2.0 fw) and I've also tested it on the luaplayer for windows alpha.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Floating point numbers have both +0 and -0. It's mostly of use to people trying to perform analytical calculations. One example is it can be used to find out if a numerical series converges to 0 and if it approached from above (+0) or below (-0).

It's not a lua bug and you probably shouldn't need to worry about it.

Jim
User avatar
dingo
Posts: 2
Joined: Thu Nov 17, 2005 5:51 am

Post by dingo »

Ooh OK, thanks for explaining that..
Post Reply