Debian bug report logs - #1732
Bad arithmetic in new perl packages

Package: perl; Reported by: Fernando <alegre@mars.superlink.net>; 9 days old.
Bug assigned to package `perl'. Request was from Ian Jackson <ian@chiark.chu.cam.ac.uk> to debian-bugs-request@pixar.com. Full text available.

Message received at debian-bugs:


From WI.LeidenUniv.NL!jdassen Tue Oct 24 01:12:27 1995
Return-Path: <jdassen@WI.LeidenUniv.NL>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t7eT9-0005xYC; Tue, 24 Oct 95 01:12 PDT
Received: from mailhost.WI.LeidenUniv.NL (zeus128.wi.leidenuniv.nl) by pixar.com with SMTP id AA21934
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Tue, 24 Oct 1995 01:10:52 -0700
Received: from ind206aa.wi.leidenuniv.nl (jdassen@ind206aa [132.229.128.222])
          by mailhost.WI.LeidenUniv.NL (8.6.10a/SBH-1.20.1-M) with ESMTP id JAA25470
          Tue, 24 Oct 1995 09:11:13 +0100 (MET)
From: jdassen@WI.LeidenUniv.NL (J.H.M.Dassen)
Organization: Leiden University,
              Dept. of Mathematics & Computer Science,
              The Netherlands
Received: from  (jdassen@localhost)
          by ind206aa.wi.leidenuniv.nl (8.6.9/FHM-1.03-S) id IAA28563
          Tue, 24 Oct 1995 08:11:12 GMT (MET)
Message-Id: <199510240811.IAA28563@ind206aa.wi.leidenuniv.nl>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages
To: lwall@scalpel.netlabs.com, perl5-porters@nicoh.com
Date: Tue, 24 Oct 1995 09:11:12 +0100 (MET)
Cc: debian-bugs@pixar.com
In-Reply-To: <9510231849.AA09797@scalpel.netlabs.com> from "Larry Wall" at Oct 23, 95 11:49:00 am
Return-Receipt-To: jdassen@WI.LeidenUniv.NL
X-Home-Page: <URL:http://www.wi.leidenuniv.nl/home/jdassen>
X-Mailer: ELM [version 2.4 PL24 (modified)]
Content-Type: text
Content-Length: 1555      

> : > Perl seems to be confused making some arithmetic operations (additions).
> : > Sometimes the result of $a+=$b, when $a is 0 and $b is 2 happens to be
> : > 2.000004192 or something similar.
> :
> : Fernando, I unfortunately have no idea what is causing this. Please
> : provide a short script which shows this behaviour (reliably if possible).
> :
> : Perl5-porters, is this a known bug?
> 
> No.  Another possibility is that the compiler is using single-precision
> instead of double-precision floats.  I think you get about 7 digits of
> accuracy in single precision.

Larry, I've forwarded Fernando's script to perl5-porters.

The perl5 package was compiled using Debian's gcc package (gcc 2.6.3)
in a.out binary format using '-O2 -fomit-frame-pointer' optimization; 
the libc is Linux libc-4.6.27.

The output differs in the 10th decimal. The weird thing is that it
appears when copying the value.

I cannot reproduce the bug on the following configurations:
FreeBSD 2.1.0,	perl 5.001m
SunOS 4.1.4,	perl 5.000
HP-UX 9,	perl 5.000
IRIX 5.3,	perl 5.000

perl5-porters, please try to reproduce this 
- on an non-linux system (with 5.001m)
- on a linux system (with a non-debian 5.001m)
- on a debian linux system under ELF   (my home-machine is not net.connected).

Regards,
Ray
-- 
LEADERSHIP  A form of self-preservation exhibited by people with auto-
destructive imaginations in order to ensure that when it comes to the crunch 
it'll be someone else's bones which go crack and not their own.       
- The Hipcrime Vocab by Chad C. Mulligan    

Acknowledgement sent to jdassen@WI.LeidenUniv.NL (J.H.M.Dassen):
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From math.ohio-state.edu!ilya Tue Oct 24 01:09:57 1995
Return-Path: <ilya@math.ohio-state.edu>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t7eQj-0005xYC; Tue, 24 Oct 95 01:09 PDT
Received: from monk.mps.ohio-state.edu by pixar.com with SMTP id AA21760
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Tue, 24 Oct 1995 01:09:23 -0700
Received: (from ilya@localhost) by monk.mps.ohio-state.edu (8.6.12/8.6.12) id EAA26616; Tue, 24 Oct 1995 04:09:13 -0400
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Message-Id: <199510240809.EAA26616@monk.mps.ohio-state.edu>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages (fwd)
To: jdassen@WI.LeidenUniv.NL (J.H.M.Dassen)
Date: Tue, 24 Oct 1995 04:09:13 -0400 (EDT)
Cc: perl5-porters@africa.nicoh.com, debian-bugs@pixar.com
In-Reply-To: <199510240745.HAA28263@ind206aa.wi.leidenuniv.nl> from "J.H.M.Dassen" at Oct 24, 95 08:45:17 am
X-Mailer: ELM [version 2.4 PL24]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 814       

J.H.M.Dassen writes:
> ------------------------------------------------------------
> #!/usr/bin/perl
> 
> @array=(
> "item1 4 units",
> "item2 1.5 units",
> "item3 8 units + see item2"
> );
> 
> foreach (@array) {
> 	if( ($item_name,$amount,$unit,$delimiter,$moreinfo)=
> 		/^(\w+)\s*([\d\.]+)\s*(\w+)\s*(\+|$)\s*(.*)/) {
> 		$total+=$amount;
> 		}
> 	}
> 
> $Total=$total;
> print "total=$total\n";
> print "Total=$Total\n";
> -----------------------------------------------------------------
> 
> Output from perl-5.001-5:
> total=13.5
> Total=13.5000000003576
> 
> Output from perl-5.001-3:
> total=13.5
> Total=13.5000000005364
> 

No problem here, OS/2, 486/66x2 (1.5 years old).

It would help if you report the version of perl (perl -v) (there is no
such guy as 5.001-5), OS, compiler. Run myconfig.

Ilya

Acknowledgement sent to Ilya Zakharevich <ilya@math.ohio-state.edu>:
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From WI.LeidenUniv.NL!jdassen Tue Oct 24 00:45:51 1995
Return-Path: <jdassen@WI.LeidenUniv.NL>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t7e3K-0006FZC; Tue, 24 Oct 95 00:45 PDT
Received: from mailhost.WI.LeidenUniv.NL (zeus128.wi.leidenuniv.nl) by pixar.com with SMTP id AA20451
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Tue, 24 Oct 1995 00:44:57 -0700
Received: from ind206aa.wi.leidenuniv.nl (jdassen@ind206aa [132.229.128.222])
          by mailhost.WI.LeidenUniv.NL (8.6.10a/SBH-1.20.1-M) with ESMTP id IAA25038
          Tue, 24 Oct 1995 08:45:18 +0100 (MET)
From: jdassen@WI.LeidenUniv.NL (J.H.M.Dassen)
Organization: Leiden University,
              Dept. of Mathematics & Computer Science,
              The Netherlands
Received: from  (jdassen@localhost)
          by ind206aa.wi.leidenuniv.nl (8.6.9/FHM-1.03-S) id HAA28263
          Tue, 24 Oct 1995 07:45:17 GMT (MET)
Message-Id: <199510240745.HAA28263@ind206aa.wi.leidenuniv.nl>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages (fwd)
To: perl5-porters@nicoh.com, debian-bugs@pixar.com
Date: Tue, 24 Oct 1995 08:45:17 +0100 (MET)
Return-Receipt-To: jdassen@WI.LeidenUniv.NL
X-Home-Page: <URL:http://www.wi.leidenuniv.nl/home/jdassen>
X-Mailer: ELM [version 2.4 PL24 (modified)]
Content-Type: text
Content-Length: 1772      

Forwarded message:
>From alegre@mars.superlink.net  Mon Oct 23 17:47:44 1995
Date: Mon, 23 Oct 1995 12:47:22 -0400 (EDT)
From: Fernando <alegre@mars.superlink.net>
To: "J.H.M.Dassen" <jdassen@WI.LeidenUniv.NL>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages
In-Reply-To: <199510221657.QAA21984@ind143a.wi.leidenuniv.nl>
Message-ID: <Pine.SGI.3.91.951023124508.27119A-100000@mars.superlink.net>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


While trying to isolate the bug in perl-5.001-5  I managed to reproduce it
also with perl-5.001-3, although the output is not exactly the same.
I have tried the script below in two machines (a 386SX and a 486DX) with 
the same result. It seems to be some conversion problem. It happens more 
often in perl-5.001m because I noticed when I upgraded and my scripts 
started to fail.

This is the test script:

------------------------------------------------------------
#!/usr/bin/perl

@array=(
"item1 4 units",
"item2 1.5 units",
"item3 8 units + see item2"
);

foreach (@array) {
	if( ($item_name,$amount,$unit,$delimiter,$moreinfo)=
		/^(\w+)\s*([\d\.]+)\s*(\w+)\s*(\+|$)\s*(.*)/) {
		$total+=$amount;
		}
	}

$Total=$total;
print "total=$total\n";
print "Total=$Total\n";
-----------------------------------------------------------------

Output from perl-5.001-5:
total=13.5
Total=13.5000000003576

Output from perl-5.001-3:
total=13.5
Total=13.5000000005364

Thanks,
	Fernando.


-- 
J.H.M. Dassen                 | RUMOUR  Believe all you hear. Your world may  
jDassen@wi.LeidenUniv.Nl      | not be a better one than the one the blocks   
Dassen@stpc.wi.LeidenUniv.Nl  | live in but it'll be a sight more vivid.      
                              |     - The Hipcrime Vocab by Chad C. Mulligan  

Acknowledgement sent to jdassen@WI.LeidenUniv.NL (J.H.M.Dassen):
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From scalpel.netlabs.com!lwall Mon Oct 23 11:55:07 1995
Return-Path: <lwall@scalpel.netlabs.com>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t7S1a-0005lrC; Mon, 23 Oct 95 11:55 PDT
Received: from proxy.netlabs.com (ns.netlabs.com) by pixar.com with SMTP id AA12485
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Mon, 23 Oct 1995 11:54:34 -0700
Received: by proxy.netlabs.com (4.1/SMI-4.1)
	id AA07250; Mon, 23 Oct 95 11:53:41 PDT
Received: from vaccine-bb.netlabs.com(192.190.199.1) by proxy.netlabs.com via smap (V1.3)
	id sma007248; Mon Oct 23 11:53:39 1995
Received: from scalpel.netlabs.com by netlabs.com (4.1/SMI-4.1)
	id AA21665; Mon, 23 Oct 95 11:50:37 PDT
Received: from localhost.netlabs.com by scalpel.netlabs.com (4.1/SMI-4.1)
	id AA09797; Mon, 23 Oct 95 11:49:18 PDT
Message-Id: <9510231849.AA09797@scalpel.netlabs.com>
To: jdassen@WI.LeidenUniv.NL (J.H.M.Dassen)
Cc: alegre@mars.superlink.net, debian-bugs@pixar.com,
        perl5-porters@africa.nicoh.com
Subject: Re: Bug#1732: Bad arithmetic in new perl packages 
In-Reply-To: Your message of "Sun, 22 Oct 95 17:57:31 BST."
             <199510221657.QAA21984@ind143a.wi.leidenuniv.nl> 
Date: Mon, 23 Oct 95 11:49:00 -0700
From: Larry Wall <lwall@scalpel.netlabs.com>

: Fernando wrote to debian-bugs:
: > Pakckage: perl
: > Version: 5.001-5
: (perl5-porters, this is 5.001m without additional packages).
: 
: > Notes: tried a.out only, happens also with 5.001-4, however 5.001-3 is OK
: (5.001-3 == 5.001e).
: 
: > Perl seems to be confused making some arithmetic operations (additions).
: > Sometimes the result of $a+=$b, when $a is 0 and $b is 2 happens to be
: > 2.000004192 or something similar.
: 
: Fernando, I unfortunately have no idea what is causing this. Please
: provide a short script which shows this behaviour (reliably if possible).
: 
: Perl5-porters, is this a known bug?

No.  Another possibility is that the compiler is using single-precision
instead of double-precision floats.  I think you get about 7 digits of
accuracy in single precision.

Larry

Acknowledgement sent to Larry Wall <lwall@scalpel.netlabs.com>:
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From lafcol.lafayette.edu!doughera Sun Oct 22 12:44:57 1995
Return-Path: <doughera@lafcol.lafayette.edu>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t76KD-0006HCC; Sun, 22 Oct 95 12:44 PDT
Received: from lafcol.lafayette.edu by pixar.com with SMTP id AA05469
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Sun, 22 Oct 1995 12:43:57 -0700
Received: by lafcol.lafayette.edu (4.1/SMI-4.1)
	id AA17910; Sun, 22 Oct 95 15:44:12 EDT
Date: Sun, 22 Oct 1995 15:44:11 -0400 (EDT)
From: Andy Dougherty <doughera@lafcol.lafayette.edu>
Sender: Andy Dougherty <doughera@lafcol.lafayette.edu>
Reply-To: Andy Dougherty <doughera@lafcol.lafayette.edu>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages
To: "J.H.M.Dassen" <jdassen@WI.LeidenUniv.NL>
Cc: alegre@mars.superlink.net, debian-bugs@pixar.com,
        perl5-porters@africa.nicoh.com
In-Reply-To: <199510221657.QAA21984@ind143a.wi.leidenuniv.nl>
Message-Id: <Pine.3.89.9510221526.A17809-0100000@lafcol>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII

On Sun, 22 Oct 1995, J.H.M.Dassen wrote:

> Fernando wrote to debian-bugs:
(problem with 5.001m, but not 5.001e)

> > Perl seems to be confused making some arithmetic operations (additions).
> > Sometimes the result of $a+=$b, when $a is 0 and $b is 2 happens to be
> > 2.000004192 or something similar.

Without seeing a short example script, it's dangerous to guess, but I'll do
so anyway.

There is a very subtle bug that can arise in some rare situations where
perl has to convert back and forth between string and floating point
representations, but that's almost certainly not the problem here. 

I also can't think of anything in 5.001m (as opposed to 5.001e) that 
might have affected this.

I'd guess one of two things is going on:

1.  This is the usual sort of problem that arises when folks forget
that floating point arithmetic isn't exact.  Perl5 is pretty forgiving, 
and tries hard to print what you want, but doesn't always succeed.

2.  The tests are running on a buggy pentium :-).
> Fernando, I unfortunately have no idea what is causing this. Please
> provide a short script which shows this behaviour (reliably if possible).

    Andy Dougherty		doughera@lafcol.lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042



Acknowledgement sent to Andy Dougherty <doughera@lafcol.lafayette.edu>:
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From WI.LeidenUniv.NL!jdassen Sun Oct 22 10:05:52 1995
Return-Path: <jdassen@WI.LeidenUniv.NL>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t73qF-000B1tC; Sun, 22 Oct 95 10:05 PDT
Received: from mailhost.WI.LeidenUniv.NL (zeus128.wi.leidenuniv.nl) by pixar.com with SMTP id AA26601
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Sun, 22 Oct 1995 09:57:54 -0700
Received: from ind143a.wi.leidenuniv.nl (jdassen@ind143a [132.229.128.229])
          by mailhost.WI.LeidenUniv.NL (8.6.10a/SBH-1.20.1-M) with ESMTP id RAA18014
          Sun, 22 Oct 1995 17:57:34 +0100 (MET)
From: jdassen@WI.LeidenUniv.NL (J.H.M.Dassen)
Organization: Leiden University,
              Dept. of Mathematics & Computer Science,
              The Netherlands
Received: from  (jdassen@localhost)
          by ind143a.wi.leidenuniv.nl (8.6.9/FHM-1.03-S) id QAA21984
          Sun, 22 Oct 1995 16:57:32 GMT (MET)
Message-Id: <199510221657.QAA21984@ind143a.wi.leidenuniv.nl>
Subject: Re: Bug#1732: Bad arithmetic in new perl packages
To: alegre@mars.superlink.net, debian-bugs@pixar.com, perl5-porters@nicoh.com
Date: Sun, 22 Oct 1995 17:57:31 +0100 (MET)
In-Reply-To: <Pine.SGI.3.91.951022123527.19473A-100000@mars.superlink.net> from "Fernando" at Oct 22, 95 12:40:47 pm
Return-Receipt-To: jdassen@WI.LeidenUniv.NL
X-Home-Page: <URL:http://www.wi.leidenuniv.nl/home/jdassen>
X-Mailer: ELM [version 2.4 PL24 (modified)]
Content-Type: text
Content-Length: 862       

Fernando wrote to debian-bugs:
> Pakckage: perl
> Version: 5.001-5
(perl5-porters, this is 5.001m without additional packages).

> Notes: tried a.out only, happens also with 5.001-4, however 5.001-3 is OK
(5.001-3 == 5.001e).

> Perl seems to be confused making some arithmetic operations (additions).
> Sometimes the result of $a+=$b, when $a is 0 and $b is 2 happens to be
> 2.000004192 or something similar.

Fernando, I unfortunately have no idea what is causing this. Please
provide a short script which shows this behaviour (reliably if possible).

Perl5-porters, is this a known bug?

Ray
-- 
PATRIOTISM  A great British writer once said that if he had to choose 
between betraying his country and betraying a friend he hoped he would
have the decency to betray his country.                                      
- The Hipcrime Vocab by Chad C. Mulligan 

Acknowledgement sent to jdassen@WI.LeidenUniv.NL (J.H.M.Dassen):
Extra info received and forwarded. Full text available.
Information forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.

Message received at debian-bugs:


From mars.superlink.net!alegre Sun Oct 22 09:37:26 1995
Return-Path: <alegre@mars.superlink.net>
Received: from pixar.com by mongo.pixar.com with smtp
	(Smail3.1.28.1 #15) id m0t73Oo-0006PjC; Sun, 22 Oct 95 09:37 PDT
Received: from jupiter.superlink.net by pixar.com with SMTP id AA26129
  (5.67b/IDA-1.5 for debian-bugs-pipe@mongo.pixar.com); Sun, 22 Oct 1995 09:36:59 -0700
Received: from earth.superlink.net (earth.superlink.net [204.97.220.6]) by jupiter.superlink.net (8.6.12/8.6.12) with ESMTP id MAA10007 for <@jupiter.superlink.net:debian-bugs@pixar.com>; Sun, 22 Oct 1995 12:36:53 -0400
Received: from mars.superlink.net by earth.superlink.net via ESMTP (950215.SGI.8.6.10/940406.SGI.AUTO)
	for <@jupiter.superlink.net:debian-bugs@pixar.com> id MAA06871; Sun, 22 Oct 1995 12:58:27 -0400
Received: by mars.superlink.net (950511.SGI.8.6.12.PATCH526/940406.SGI)
	 id MAA19702; Sun, 22 Oct 1995 12:40:48 -0400
Date: Sun, 22 Oct 1995 12:40:47 -0400 (EDT)
From: Fernando <alegre@mars.superlink.net>
To: debian-bugs@pixar.com
Subject: Bad arithmetic in new perl packages
Message-Id: <Pine.SGI.3.91.951022123527.19473A-100000@mars.superlink.net>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


Pakckage: perl
Version: 5.001-5
Notes: tried a.out only, happens also with 5.001-4, however 5.001-3 is OK

Perl seems to be confused making some arithmetic operations (additions).
Sometimes the result of $a+=$b, when $a is 0 and $b is 2 happens to be
2.000004192 or something similar.


Acknowledgement sent to Fernando <alegre@mars.superlink.net>:
New bug report received and forwarded.

Your message didn't have a Package: line at the start (in the pseudo-header following the real mail header), or didn't have a psuedo-header at all.

This makes it much harder for us to categorise and deal with your problem report; please ensure that you say which package(s) and version(s) the problem is with next time. Some time in the future the problem reports system may start rejecting such messages.

Full text available.


Report forwarded to debian-devel@pixar.com:
Bug#1732. Full text available.
Ian Jackson / iwj10@thor.cam.ac.uk, with the debian-bugs tracking mechanism
This page last modified 07:43:01 GMT Wed 01 Nov