Apparent modulo error

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

Apparent modulo error

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

Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

Gé Weijers
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



Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

Luiz Henrique de Figueiredo
In reply to this post by gtravis
> I am getting the following modulo result
> > = 9%3
> -0
> Negative zero?  Has anyone seen this. Macintosh version?

I can reproduce this. Apparently it is due to a gcc optimization because
I get 0 when I rebuild Lua with -O0. I'll try to look further into this.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
Greetings from South Texas Luiz,
I have played with the result, and something I tried is:
> = 0 == 9%3
true
> =0 < 9%3
false
> = 9 * 9%3
-0
Perhaps it is only cosmetic?  I have just started learning lua, so there are many things that I need educate myself on.
Thanks,
trav


Luiz Henrique de Figueiredo wrote:
I am getting the following modulo result
    
= 9%3
      
-0
Negative zero?  Has anyone seen this. Macintosh version?
    

I can reproduce this. Apparently it is due to a gcc optimization because
I get 0 when I rebuild Lua with -O0. I'll try to look further into this.
--lhf

  

Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
In reply to this post by Gé Weijers
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




Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
In reply to this post by Gé Weijers
Can anyone tell me what this refers to when it shows up in an error message?
' [C]: ?  '
thanks





Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

Romulo Bahiense
gtravis wrote:
Can anyone tell me what this refers to when it shows up in an error message?
' [C]: ?  '
thanks







It means the error occurred inside a C function :)

--rb

Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
Romulo,
Thank you very much.
trav

Romulo Bahiense wrote:
gtravis wrote:
Can anyone tell me what this refers to when it shows up in an error message?
' [C]: ?  '
thanks







It means the error occurred inside a C function :)

--rb



Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
In reply to this post by Luiz Henrique de Figueiredo
Luiz,
I have found that I also get the -0 in version 5.1.1.
trav


Luiz Henrique de Figueiredo wrote:
I am getting the following modulo result
    
= 9%3
      
-0
Negative zero?  Has anyone seen this. Macintosh version?
    

I can reproduce this. Apparently it is due to a gcc optimization because
I get 0 when I rebuild Lua with -O0. I'll try to look further into this.
--lhf

  

Reply | Threaded
Open this post in threaded view
|

Re: Apparent modulo error

gtravis
In reply to this post by Luiz Henrique de Figueiredo
Luiz,
I have been reading various documents and books, however, I can't find how to rebuild Lua.
trav

Luiz Henrique de Figueiredo wrote:
I am getting the following modulo result
    
= 9%3
      
-0
Negative zero?  Has anyone seen this. Macintosh version?
    

I can reproduce this. Apparently it is due to a gcc optimization because
I get 0 when I rebuild Lua with -O0. I'll try to look further into this.
--lhf