lua-users home
lua-l archive

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


Howdy Ge,
I played around just as you did below.   I did see this
> = 9 * 9%3
-0
> = -9 * 9%3
-0
I remember reading in the book that I am learning out of; Beginning Lua Programming; is that 0 is both positive and negative.
Interesting eh?
trav

Gé Weijers wrote:
Hi,

On Jun 2, 2007, at 9:44 AM, gtravis wrote:

Howdy,
I am getting the following modulo result
> = 9%3
-0
Negative zero?  Has anyone seen this. Macintosh version?

It's still 0.
>=9%3
-0

>=9%3==0
true

>=9%3+0
0

Floating point formats do not use a two's complement representation, but a separate sign bit, so there are two representations for 0.0. The comparison operators threat them as the same value.

Some earlier computers (Control Data Cyber etc.) used one's complement for integers, so you had two representations of 0 there as well.




Gé Weijers