summaryrefslogtreecommitdiff
path: root/t/base
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-02-26 11:17:42 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-26 11:17:42 +0000
commit494244503fd690687b35aca99f4243ed5667eb4f (patch)
tree9b0f08d8b9d4df46ffdd0205faf0c01f8fc81cce /t/base
parent0968fb3b097c0b37efe2c4931ddc732e32f3421a (diff)
downloadperl-494244503fd690687b35aca99f4243ed5667eb4f.tar.gz
Cray FP strikes again: things like 1.1 + 0.1 are easily
1.1999999999999996, or thereabouts (yes, even sprintf). p4raw-id: //depot/perl@14884
Diffstat (limited to 't/base')
-rw-r--r--t/base/num.t15
1 files changed, 10 insertions, 5 deletions
diff --git a/t/base/num.t b/t/base/num.t
index b3cde2e866..f75e73d428 100644
--- a/t/base/num.t
+++ b/t/base/num.t
@@ -68,20 +68,25 @@ print $a + 1 == 2 ? "ok 18\n" : "not ok 18 #" . $a + 1 . "\n";
$a = -1.; "$a";
print $a + 1 == 0 ? "ok 19\n" : "not ok 19 #" . $a + 1 . "\n";
+sub ok { # Can't assume too much of floating point numbers.
+ my ($a, $b, $c);
+ abs($a - $b) <= $c;
+}
+
$a = 0.1; "$a";
-print $a + 1 == 1.1 ? "ok 20\n" : "not ok 20 #" . $a + 1 . "\n";
+print ok($a + 1, 1.1, 0.05) ? "ok 20\n" : "not ok 20 #" . $a + 1 . "\n";
$a = -0.1; "$a";
-print $a + 1 == 0.9 ? "ok 21\n" : "not ok 21 #" . $a + 1 . "\n";
+print ok($a + 1, 0.9, 0.05) ? "ok 21\n" : "not ok 21 #" . $a + 1 . "\n";
$a = .1; "$a";
-print $a + 1 == 1.1 ? "ok 22\n" : "not ok 22 #" . $a + 1 . "\n";
+print ok($a + 1, 1.1, 0.005) ? "ok 22\n" : "not ok 22 #" . $a + 1 . "\n";
$a = -.1; "$a";
-print $a + 1 == 0.9 ? "ok 23\n" : "not ok 23 #" . $a + 1 . "\n";
+print ok($a + 1, 0.9, 0.05) ? "ok 23\n" : "not ok 23 #" . $a + 1 . "\n";
$a = 10.01; "$a";
-print $a + 1 == 11.01 ? "ok 24\n" : "not ok 24 #" . $a + 1 . "\n";
+print ok($a + 1, 11.01, 0.005) ? "ok 24\n" : "not ok 24 #" . $a + 1 . "\n";
$a = 1e3; "$a";
print $a + 1 == 1001 ? "ok 25\n" : "not ok 25 #" . $a + 1 . "\n";