[svn:parrot] r40544 - in trunk: src/dynoplibs t/dynoplibs
dukeleto at svn.parrot.org
dukeleto at svn.parrot.org
Fri Aug 14 14:25:43 UTC 2009
Author: dukeleto
Date: Fri Aug 14 14:25:41 2009
New Revision: 40544
URL: https://trac.parrot.org/parrot/changeset/40544
Log:
[TT #871] Add srand() as a dynop
Modified:
trunk/src/dynoplibs/math.ops
trunk/t/dynoplibs/math.t
Modified: trunk/src/dynoplibs/math.ops
==============================================================================
--- trunk/src/dynoplibs/math.ops Fri Aug 14 07:29:32 2009 (r40543)
+++ trunk/src/dynoplibs/math.ops Fri Aug 14 14:25:41 2009 (r40544)
@@ -57,6 +57,27 @@
$1 = $2 + ($3 - $2) * Parrot_float_rand(0);
}
+=item B<srand>(in NUM)
+
+Set the random number seed to $1.
+
+=cut
+
+inline op srand(in NUM) {
+ Parrot_srand((FLOATVAL)$1);
+}
+
+=item B<srand>(in INT)
+
+Set the random number seed to $1.
+
+=cut
+
+inline op srand(in INT) {
+ Parrot_srand((INTVAL)$1);
+}
+
+
=back
=head1 COPYRIGHT
Modified: trunk/t/dynoplibs/math.t
==============================================================================
--- trunk/t/dynoplibs/math.t Fri Aug 14 07:29:32 2009 (r40543)
+++ trunk/t/dynoplibs/math.t Fri Aug 14 14:25:41 2009 (r40544)
@@ -19,11 +19,13 @@
.loadlib 'math_ops'
.sub main :main
.include 'test_more.pir'
- plan(7)
+ .include 'fp_equality.pasm'
+ plan(10)
ok(1, "load math_ops")
basic_test_1_arg()
basic_test_2_arg()
basic_test_3_arg()
+ test_srand()
.end
.sub basic_test_1_arg
@@ -74,6 +76,19 @@
finish:
.end
+.sub test_srand
+ srand 42
+ ok(1, 'call srand with int')
+ srand 42.0
+ ok(1, 'call srand with num')
+ rand $N0
+ srand 5
+ rand $N2
+ srand 42.0
+ rand $N1
+ .fp_eq_ok($N0, $N1, 'having the same seed generates the same numbers')
+.end
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list