From c513fbdf55d2d891a2e97e06ffc74a59904e0e0e Mon Sep 17 00:00:00 2001 From: Solomon Foster Date: Fri, 16 Jul 2010 10:26:19 -0400 Subject: [PATCH] Make sure calling .rand on a Complex number doesn't cause an infinite recursion. --- src/core/Numeric.pm | 8 ++++++++ src/core/Real.pm | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/Numeric.pm b/src/core/Numeric.pm index 9dc4cb3c53c..0e31c3606ab 100644 --- a/src/core/Numeric.pm +++ b/src/core/Numeric.pm @@ -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"; @@ -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); +} diff --git a/src/core/Real.pm b/src/core/Real.pm index c98737fb2dd..5be4f801f04 100644 --- a/src/core/Real.pm +++ b/src/core/Real.pm @@ -96,7 +96,7 @@ role Real does Numeric { $mag * $angle.sin(Radians)); } - method rand($x:) { + method rand(Real $x:) { $x.Bridge.rand; }