Skip to content

Commit

Permalink
Implement log2 function
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrowder committed Nov 21, 2019
1 parent c745d6b commit f6254be
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core.c/Cool.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ my class Cool { # declared in BOOTSTRAP
multi method round($base) { self.Numeric.round($base) }

method roots(Cool $n) { self.Numeric.roots($n) }
method log2() { self.Numeric.log2 }
method log10() { self.Numeric.log10 }
method unpolar($n) { self.Numeric.unpolar($n.Numeric) }

Expand Down
5 changes: 5 additions & 0 deletions src/core.c/Numeric.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ my role Numeric {
multi method log(Numeric:D: Cool $base) { self.log / $base.Numeric.log }
multi method log(Numeric:D: Numeric $base) { self.log / $base.log }

method log2() { self.log / 2e0.log }
method log10() { self.log / 10e0.log }

proto method exp(|) {*}
Expand Down Expand Up @@ -76,6 +77,10 @@ multi sub log(Numeric $x, Numeric $base) { $x.log($base) }
multi sub log(Cool $x) { $x.Numeric.log }
multi sub log(Cool $x, Cool $base) { $x.Numeric.log($base.Numeric) }

proto sub log2($, *%) is pure {*}
multi sub log2(Numeric $x) { $x.log(2e0) }
multi sub log2(Cool $x) { $x.Numeric.log(2e0) }

proto sub log10($, *%) is pure {*}
multi sub log10(Numeric $x) { $x.log(10e0) }
multi sub log10(Cool $x) { $x.Numeric.log(10e0) }
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6c.t
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ my @expected = (
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6d.t
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ my @expected = (
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6e.t
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ my @expected = (
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys.t
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ my @allowed =
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6c.t
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ my %allowed = (
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6e.t
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ my %allowed = (
Q{&list},
Q{&log},
Q{&log10},
Q{&log2},
Q{&lsb},
Q{&make},
Q{&map},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/12-proto-arity-count.t
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ sub all-the-protos {
&list,
&log,
&log10,
&log2,
&lsb,
&make,
&map,
Expand Down

0 comments on commit f6254be

Please sign in to comment.