develooper Front page | perl.perl5.porters | Postings from January 2001

[ID 20010104.010] Inconsistent arithmetic with % and * operators

Thread Next
From:
dickinsm
Date:
January 4, 2001 18:10
Subject:
[ID 20010104.010] Inconsistent arithmetic with % and * operators
Message ID:
Pine.SOL.3.96-4hack.1010104210707.18359A-100000@justice.math.lsa.umich.edu
This is a bug report for perl from dickinsm@math.lsa.umich.edu,
generated with the help of perlbug 1.33 running under perl v5.6.1.

# The following complete four-line perl script produces unexpected
# results on my machine.  The multiplication in the second line of
# code below produces a negative result where a positive number is
# expected, presumably because an integer multiplication was used
# internally where a floating point operation was needed.  If the
# expression is broken up and evaluated piece by piece then the
# correct result is produced (line 4). (The difference between the two
# results is, naturally, 2**32.)  The same results were produced under
# perl v5.6.0.

my ($p, $x, $y) = (65537, 64645, 34463);
print (($x % $p) * ($y % $p), "\n");     # produces -2067106661 (incorrect)
my ($a, $b) = ($x % $p, $y % $p); 
print $a * $b, "\n";                     # produces  2227860635 (correct)

---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.6.1:

Configured by root at Thu Jan  4 20:24:41 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.2.16, archname=i686-linux
    uname='linux piglit 2.2.16 #1 wed aug 2 20:03:33 gmt 2000 i686 unknown '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    v5.6.1-TRIAL1

---
@INC for perl v5.6.1:
    /usr/local/lib/perl5/5.6.1/i686-linux
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/i686-linux
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.0/i686-linux
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.6.1:
    HOME=/home/mark
    LANG=en_US
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/mark/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/lib/java/bin:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/bash



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About