Skip to content

Commit

Permalink
Make sure calling .rand on a Complex number doesn't cause an infinite…
Browse files Browse the repository at this point in the history
… recursion.
  • Loading branch information
colomon committed Jul 16, 2010
1 parent 9dae675 commit c513fbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/core/Numeric.pm
Expand Up @@ -132,6 +132,10 @@ role Numeric {
fail "unpolar is only defined for Reals, you have a $.WHAT()";
}

method rand(Numeric $x:) {
$x.Real.rand;
}

method sin(Numeric $x: $base = Radians) {
note "$.WHAT() needs a version of .sin";
fail "$.WHAT() needs a version of .sin";
Expand Down Expand Up @@ -296,3 +300,7 @@ multi sub infix:«<=»(Numeric $a, Numeric $b) {
multi sub infix>=»(Numeric $a, Numeric $b) {
($a <=> $b) != -1;
}

multi sub srand(Numeric $seed) {
srand($seed.Real);
}
2 changes: 1 addition & 1 deletion src/core/Real.pm
Expand Up @@ -96,7 +96,7 @@ role Real does Numeric {
$mag * $angle.sin(Radians));
}

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

Expand Down

0 comments on commit c513fbd

Please sign in to comment.