develooper Front page | perl.perl5.porters | Postings from July 2003

Re: [PATCH] Re: Oops - Can't calculate our powers

Thread Previous | Thread Next
From:
Andreas J Koenig
Date:
July 18, 2003 00:37
Subject:
Re: [PATCH] Re: Oops - Can't calculate our powers
Message ID:
87fzl4thf4.fsf@franz.ak.mind.de
Stephen McCamant <smcc@mit.edu> writes:


> --- t/op/pow.t.orig	2003-07-07 20:04:12.000000000 -0400
> +++ t/op/pow.t	2003-07-18 02:09:20.000000000 -0400

Adding your test on -3 does not catch the bug on my box. For some
reason Tim's testcase printed only OKs for me and -3**3 just works.
But after some trying I found a test that failed here: -3**1 returned
+3 under some circumstances. So I'd suggest using this patch instead,
it also gives better diagnostics:

--- perl-p-5.8.0@20166/t/op/pow.t	2002-06-01 19:03:49.000000000 +0200
+++ perl-p-5.8.0@20166-ak/t/op/pow.t	2003-07-18 08:45:43.000000000 +0200
@@ -12,7 +12,13 @@
 
 # 3**30 < 2**48, don't trust things outside that range on a Cray
 # Likewise other 3 should not overflow 48 bits if I did my sums right.
-my @pow = ([3,30,1e-14], [4,32,0], [5,20,1e-14], [2.5, 10,,1e-14], [-2, 69,0]);
+my @pow = ([3,30,1e-14],
+           [4,32,0],
+           [5,20,1e-14],
+           [2.5, 10,,1e-14],
+           [-2, 69,0],
+           [-3, 30,0],
+);
 my $tests;
 $tests += $_->[1] foreach @pow;
 
@@ -30,17 +36,17 @@
 # perfect, forgetting that it's a call to floating point pow() which never
 # claims to deliver perfection.
 foreach my $n (0..$bits_in_uv - 1) {
-    my $exp = 2 ** $n;
+    my $pow = 2 ** $n;
     my $int = 1 << $n;
-    cmp_ok ($exp, '==', $int, "2 ** $n vs 1 << $n");
+    cmp_ok ($pow, '==', $int, "2 ** $n vs 1 << $n");
 }
 
 foreach my $pow (@pow) {
     my ($base, $max, $range) = @$pow;
-    my $fp = 1;
+    my $expect = 1;
     foreach my $n (0..$max-1) {
-        my $exp = $base ** $n;
-        within ($exp, $fp, $range, "$base ** $n [$exp] vs $base * $base * ...");
-        $fp *= $base;
+        my $got = $base ** $n;
+        within ($got, $expect, $range, "$base ** $n got[$got] expect[$expect]");
+        $expect *= $base;
     }
 }


-- 
andreas

Thread Previous | 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