MLUG: Re: [UUG/MLUG] perl and y2k
Re: [UUG/MLUG] perl and y2k
Email address obfuscation in effect -- please click here to turn it off.

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

On Wed, 5 Jan 2000, Stephen Montgomery-Smith wrote:

> Jonathan King wrote:
>

[snip]

> > Along these lines, and while we all run off to fix our code, some of you
> > might be interested in the fact that perl does something potentially
> > unexpected with the % operator when the first argument is negative, so
> > that:
> > 
> >     [EMAIL:PROTECTED]$ perl -e '$a=-98; printf("%02d\n",$a%100);'
> >     02
> > 
> 
> Hmmm, in my opinion (as a mathematician) that is the correct answer.
> I would have expected -98 (in my opinion the wrong answer, but
> what I think C does).

Curiousity caused the cat:

    [EMAIL:PROTECTED king]$ cat > triv.c
    int main () {
    printf("%d\n", -98%100);
    }
    [EMAIL:PROTECTED king]$ cc -o triv triv.c
    [EMAIL:PROTECTED king]$ triv
    bash: triv: command not found

Hmm...I wonder why this happened. :-)

    [EMAIL:PROTECTED king]$ ./triv
    -98

And, indeed, it is the fact that both C and awk diverges from mathematical
convention that causes people to blame perl for a "wrong" answer in this
case.

jking