diff options
-rw-r--r-- | t/base/num.t | 15 |
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"; |