Skip to content

Commit

Permalink
Adjust rand and srand to conform more to our current way of doing thi…
Browse files Browse the repository at this point in the history
…ngs.
  • Loading branch information
colomon committed Jul 16, 2010
1 parent c7edce6 commit 9dae675
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/Cool-num.pm
Expand Up @@ -67,8 +67,8 @@ augment class Cool {
~(pir::chr__SI(self))
}

our Num method rand() {
pir::box__PN(pir::rand__NN(self))
method rand($x:) {
(+$x).rand;
}

method sin($x: $base = Radians) {
Expand Down Expand Up @@ -312,8 +312,8 @@ proto chr($graph) {
$graph.chr;
}

sub srand(Int $seed = time) {
pir::srand__0I($seed);
proto sub srand($seed) {
srand(+$seed);
}

# vim: ft=perl6
4 changes: 4 additions & 0 deletions src/core/Num.pm
Expand Up @@ -75,6 +75,10 @@ augment class Num does Real {
}
}

method rand(Num $x:) {
pir::box__PN(pir::rand__NN($x))
}

method sin(Num $x: $base = Radians) {
pir::sin__Nn($x.to-radians($base));
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/Real.pm
Expand Up @@ -96,6 +96,10 @@ role Real does Numeric {
$mag * $angle.sin(Radians));
}

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

method sin(Real $x: $base = Radians) {
$x.Bridge.sin($base);
}
Expand Down Expand Up @@ -264,3 +268,7 @@ multi sub infix:<**>(Real $a, Real $b) {
our multi sub infix:<mod>(Real $a, Real $b) {
$a - ($a div $b) * $b;
}

multi sub srand(Real $seed = time) {
pir::srand__0I($seed.Int);
}

0 comments on commit 9dae675

Please sign in to comment.