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

[email protected] (Sascha Schumann)
Newsgroups php.dev
Message-ID <[email protected]>
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 adhere to the mathematical definition.

    ISO C truncates towards zero.  It specifically says in 6.5.5
    Multiplicative Operators:

    If the quotient a/b is representable, the expression (a/b)*b
    + a%b shall equal a.

    So -27 % 7 yields -6.

    - Sascha
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.