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

[PATCH: perl@8482] floating point mangling warnings for README.os390and README.posix-bc

Thread Next
From:
Peter Prymmer
Date:
January 19, 2001 13:46
Subject:
[PATCH: perl@8482] floating point mangling warnings for README.os390and README.posix-bc
Message ID:
Pine.OSF.4.10.10101191347140.59299-100000@aspara.forte.com

This revised patch taken w.r.t. 8482 incorporates the suggestions 
von Herrn Dorner und von Herrn Newton.  It gives users the warnings
about floating point round off errors that they may encounter while
programming in perl on the respective S/390 OSes:

diff -ru perl.8482.orig/README.os390 perl.8482/README.os390
--- perl.8482.orig/README.os390	Fri Jan 19 13:20:20 2001
+++ perl.8482/README.os390	Fri Jan 19 13:22:12 2001
@@ -278,6 +278,40 @@
 for an example of how to use the "eval exec" trick to ask the shell to
 have Perl run your scripts on those older releases of Unix System Services.
 
+=head2 Floating point anomalies
+
+There appears to be a bug in the floating point implementation on S/390 
+systems such that calling int() on the product of a number and a small 
+magnitude number is not the same as calling int() on the quotient of 
+that number and a large magnitude number.  For example, in the following 
+Perl code:
+
+    my $x = 100000.0;
+    my $y = int($x * 1e-5) * 1e5; # '0'
+    my $z = int($x / 1e+5) * 1e5;  # '100000'
+    print "\$y is $y and \$z is $z\n"; # $y is 0 and $z is 100000
+
+Although one would expect the quantities $y and $z to be the same and equal 
+to 100000 they will differ and instead will be 0 and 100000 respectively.
+
+The problem can be further examined in a roughly equivalent C program:
+
+    #include <stdio.h>
+    #include <math.h>
+    main()
+    {
+    double r1,r2;
+    double x = 100000.0;
+    double y = 0.0;
+    double z = 0.0;
+    x = 100000.0 * 1e-5;
+    r1 = modf (x,&y);
+    x = 100000.0 / 1e+5;
+    r2 = modf (x,&z);
+    printf("y is %e and z is %e\n",y*1e5,z*1e5);
+    /* y is 0.000000e+00 and z is 1.000000e+05 (with c89) */
+    }
+
 =head2 Modules and Extensions
 
 Pure pure (that is non xs) modules may be installed via the usual:
@@ -308,6 +342,7 @@
 David Fiander and Peter Prymmer with thanks to Dennis Longnecker
 and William Raffloer for valuable reports, LPAR and PTF feedback.
 Thanks to Mike MacIsaac and Egon Terwedow for SG24-5944-00.
+Thanks to Ignasi Roca for pointing out the floating point problems.
 
 =head1 SEE ALSO
 
@@ -332,9 +367,14 @@
 
     subscribe perl-mvs
 
-to majordomo@perl.org.  There is a web archive of the mailing list at:
+to majordomo@perl.org.   See also:
+
+    http://lists.perl.org/showlist.cgi?name=perl-mvs
+
+There are web archives of the mailing list at:
 
     http://www.xray.mpe.mpg.de/mailing-lists/perl-mvs/
+    http://archive.develooper.com/perl-mvs@perl.org/
 
 =head1 HISTORY
 
@@ -345,5 +385,7 @@
 
 Updated 12 November 2000 for the 5.7.1 release of Perl.
 
+Updated 15 January 2001 for the 5.7.1 release of Perl.
+
 =cut
 
diff -ru perl.8482.orig/README.posix-bc perl.8482/README.posix-bc
--- perl.8482.orig/README.posix-bc	Fri Jan 19 13:20:20 2001
+++ perl.8482/README.posix-bc	Fri Jan 19 13:25:59 2001
@@ -134,6 +134,22 @@
     eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
         if $running_under_some_shell;
 
+=head2 Floating point anomalies
+
+There appears to be a bug in the floating point implementation on BS2000 POSIX
+systems such that calling int() on the product of a number and a small
+magnitude number is not the same as calling int() on the quotient of
+that number and a large magnitude number.  For example, in the following
+Perl code:
+
+    my $x = 100000.0;
+    my $y = int($x * 1e-5) * 1e5; # '0'
+    my $z = int($x / 1e+5) * 1e5;  # '100000'
+    print "\$y is $y and \$z is $z\n"; # $y is 0 and $z is 100000
+
+Although one would expect the quantities $y and $z to be the same and equal
+to 100000 they will differ and instead will be 0 and 100000 respectively.
+
 =head1 AUTHORS
 
 Thomas Dorner
End of Patch.

Peter Prymmer



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