Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread Rasmus Lerdorf
On Tue, 4 Mar 2003, Sascha Schumann wrote: > > Well, Perl can lean the other way as well actually. Try this: > > Is there some documentation why the default is as it is? All I could find was this description of the Perl modulus operator: Binary ``%'' computes the modulus of two numbers.

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread Sascha Schumann
> Well, Perl can lean the other way as well actually. Try this: Is there some documentation why the default is as it is? > You will see it gives you -6. Like I said, it comes down to which way you > truncate. Programmers tend to think that something like (int)(-3.4) > should result in -3.

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread Rasmus Lerdorf
Well, Perl can lean the other way as well actually. Try this: use integer; print -27%7; You will see it gives you -6. Like I said, it comes down to which way you truncate. Programmers tend to think that something like (int)(-3.4) should result in -3. If that is what you expect, then I t

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread Sascha Schumann
> Yeah, I read that in the bug report and confirmed that as the intended > behavior in C. What I meant was 'regardless of what the ISO standard > says, thats not a standard mathematical definition.' Well, the standard mathematical definition r = a mod b <=> a = floor(a/b) * b + r

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread George Schlossnagle
On Tuesday, March 4, 2003, at 10:33 AM, Sascha Schumann wrote: On Tue, 4 Mar 2003, George Schlossnagle wrote: Interesting. I don't know what the ISO standard say, but mathematically a a % b will always return you an integer 0 <= a%b < b (since there are no negative numbers in canonical represe

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread Sascha Schumann
On Tue, 4 Mar 2003, George Schlossnagle wrote: > Interesting. > > I don't know what the ISO standard say, but mathematically a a % b will > always return you an integer 0 <= a%b < b (since there are no negative > numbers in canonical representation of Z/bZ). I guess perl/python/tcl > ddecided to

Re: [PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-04 Thread George Schlossnagle
Interesting. I don't know what the ISO standard say, but mathematically a a % b will always return you an integer 0 <= a%b < b (since there are no negative numbers in canonical representation of Z/bZ). I guess perl/python/tcl ddecided to adhere to the mathematical definition. On Tuesday, Marc

[PHP-DEV] Re: #22527 [Opn->Bgs]: Modulus returned negative value

2003-03-03 Thread Rasmus Lerdorf
This is actually an interesting question. Should we be truncating towards zero? I'd say yes, but then I tested Perl, Python and Tcl, and they all say that -27 % 7 is 1 which means they truncate towards negative infinity. Too late to change at this point in the game, but perhaps it calls for a mo