Skip to content

Commit

Permalink
Tidy up Numeric and Real.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jun 12, 2010
1 parent d59da85 commit e22e80f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/core/Numeric.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ role Numeric {
fail "$.WHAT() needs a version of .abs";
}

multi method exp(Numeric $exponent: Numeric $base = e) {
method exp(Numeric $exponent: Numeric $base = e) {
note "$.WHAT() needs a version of .exp";
fail "$.WHAT() needs a version of .exp";
}
Expand Down Expand Up @@ -203,12 +203,12 @@ role Numeric {
}
}

multi sub infixcmp»(Numeric $a, Numeric $b) { $a <=> $b; }

multi sub postfix:<i>(Numeric $z) {
$z * 1i;
}

multi sub infixcmp»(Numeric $a, Numeric $b) { $a <=> $b; }

multi sub infix:«<=>»(Numeric $a, Numeric $b) {
my @a = $a.reals;
my @b = $b.reals;
Expand Down
30 changes: 15 additions & 15 deletions src/core/Real.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,27 @@ role Real does Numeric {
$x.Bridge.ln;
}

method sqrt(Real $x:) {
$x.Bridge.sqrt;
}

method roots(Real $x: Int $n) {
$x.Complex.roots($n);
}

method sign(Real $x:) {
$x.notdef ?? Mu
!! ($x ~~ NaN ?? NaN !! $x <=> 0);
}

method ceiling(Real $x:) {
$x.Bridge.ceiling;
}

method floor(Real $x:) {
$x.Bridge.floor;
}

method ceiling(Real $x:) {
$x.Bridge.ceiling;
}

method truncate(Real $x:) {
$x == 0 ?? 0 !! $x < 0 ?? $x.ceiling !! $x.floor
}
Expand All @@ -71,21 +79,13 @@ role Real does Numeric {
floor($x / $scale + 0.5) * $scale;
}

method unpolar(Real $mag: Real $angle) {
Complex.new($mag * $angle.cos(Radians),
$mag * $angle.sin(Radians));
}

method cis(Real $angle:) {
1.unpolar($angle);
}

method sqrt(Real $x:) {
$x.Bridge.sqrt;
}

method roots(Real $x: Int $n) {
$x.Complex.roots($n);
method unpolar(Real $mag: Real $angle) {
Complex.new($mag * $angle.cos(Radians),
$mag * $angle.sin(Radians));
}

method sin(Real $x: $base = Radians) {
Expand Down

0 comments on commit e22e80f

Please sign in to comment.