Skip to content

Commit 6d67680

Browse files
committed
Add a test for nqp::log_n.
1 parent cd0db4e commit 6d67680

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/nqp/83-log.t

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plan(2);
2+
3+
# Basic tests for nqp::log_n
4+
5+
my $log_5 := 940945/584642;
6+
my $log_one_tenth := -254834/110673;
7+
8+
sub is_approx($got, $expected, $descr = "$got is approximately $expected") {
9+
my $tol := nqp::abs_n($expected) < 1e-6 ?? 1e-5 !! nqp::abs_n($expected) * 1e-6;
10+
my $test := nqp::abs_n($got - $expected) <= $tol;
11+
ok(?$test, $descr);
12+
unless $test {
13+
say("#got: $got");
14+
say("#expected: $expected");
15+
}
16+
?$test;
17+
}
18+
19+
is_approx(nqp::log_n(5), $log_5, 'got the log of 5');
20+
is_approx(nqp::log_n(0.1), $log_one_tenth, 'got the log of 0.1');

0 commit comments

Comments
 (0)