Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

lots of Cool methods, run cool-num.t

  • Loading branch information...
commit 3b66c0fb0cc9335f8886afd9445dc7f44523eb0d 1 parent b729151
@moritz moritz authored
View
4 src/core/Complex.pm
@@ -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 {
@@ -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
View
24 src/core/Cool.pm
@@ -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 }
@@ -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() {
View
2  src/core/Numeric.pm
@@ -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) }
View
4 src/core/Real.pm
@@ -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 }
@@ -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);
}
View
2  t/spectest.data
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.