Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
lots of Cool methods, run cool-num.t
  • Loading branch information
moritz committed Aug 22, 2011
1 parent b729151 commit 3b66c0f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/core/Complex.pm
Expand Up @@ -78,7 +78,8 @@ my class Complex is Numeric {
Complex.new($mag * $!im.cos, $mag * $!im.sin);
}

method roots(Complex:D: Int $n) {
method roots(Complex:D: $an) {
my Int $n = $an.Int;
return $NaN if $n < 1;
return self if $n == 1;
for $!re, $!im {
Expand Down Expand Up @@ -387,5 +388,6 @@ proto postfix:<i>(|$) { * }
multi postfix:<i>(Real \$a) { Complex.new(0e0, $a); }
multi postfix:<i>(Complex:D \$a) { Complex.new(-$a.im, $a.re) }
multi postfix:<i>(Numeric \$a) { $a * Complex.new(0e0, 1e0) }
multi postfix:<i>(Cool \$a) { $a.Numeric * Complex.new(0e0, 1e0) }

# vim: ft=perl6
24 changes: 23 additions & 1 deletion src/core/Cool.pm
Expand Up @@ -4,8 +4,11 @@ my class Cool {

## numeric methods

method abs() { self.Numeric.abs }
method conjugate() { self.Numeric.conjugate }
method sqrt() { self.Numeric.sqrt }
method sign() { self.Numeric.sign }
method rand() { self.Num.rand }
method truncate() { self.Numeric.truncate }
method sin() { self.Numeric.sin }
method asin() { self.Numeric.asin }
method cos() { self.Numeric.cos }
Expand All @@ -31,7 +34,26 @@ my class Cool {
method acosech() { self.Numeric.acosech }
method cotanh() { self.Numeric.cotanh }
method acotanh() { self.Numeric.acotanh }
method cis() { self.Numeric.cis }

proto method log(|$) {*}
multi method log() { self.Numeric.log }
multi method log($base) { self.Numeric.log($base.Numeric) }

proto method exp(|$) {*}
multi method exp() { self.Numeric.exp }
multi method exp($base) { self.Numeric.exp($base.Numeric) }


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

method round($base = 1) { self.Numeric.round($base) }
method floor() { self.Numeric.floor }
method ceiling() { self.Numeric.ceiling }
method truncate() { self.Numeric.truncate }

## string methods

method bytes() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Numeric.pm
Expand Up @@ -11,7 +11,7 @@ my class Numeric {
method log10() { self.log / 10e0.log }

proto method exp(|$) {*}
multi method exp(Numeric $base) {
multi method exp($base) {
$base ** self;
}
method roots(Cool $n) { self.Complex.roots($n.Int) }
Expand Down
4 changes: 4 additions & 0 deletions src/core/Real.pm
Expand Up @@ -7,6 +7,7 @@ my class Real {
proto method sign(|$) {*}
multi method sign(Real:U:) { Mu }
multi method sign(Real:D:) { self < 0 ?? -1 !! self == 0 ?? 0 !! 1 }
method conjugate(Real:D:) { self }
method sqrt() { self.Bridge.sqrt }
method sin() { self.Bridge.sin }
method asin() { self.Bridge.asin }
Expand Down Expand Up @@ -37,6 +38,9 @@ my class Real {
method acotanh() { self.Bridge.acotanh }
method floor() { self.Bridge.floor }
method ceiling() { self.Bridge.ceiling }
# causes "get_string() not implemented in class 'Int'"
# if commented out, but should be there
# method round($scale = 1) { (self / $scale + 0.5).floor * $scale }
method unpolar(Real $angle) {
Complex.new(self * $angle.cos, self * $angle.sin);
}
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -518,7 +518,7 @@ S32-list/roll.t
S32-num/abs.t
S32-num/base.t
S32-num/complex.t
# S32-num/cool-num.t # err: Method 'abs' not found for invocant of class 'Str'
S32-num/cool-num.t
S32-num/exp.t
S32-num/int.t
S32-num/log.t
Expand Down

0 comments on commit 3b66c0f

Please sign in to comment.