14 math.ops - Mathematical Opcodes
20 Parrot's library of mathematical ops.
22 To use this library of ops, add this directive to your PIR:
30 =item B<rand>(out NUM)
32 Set $1 to a random floating point number between 0 and 1, inclusive.
36 inline op rand(out NUM) {
37 $1 = Parrot_float_rand(0);
40 =item B<rand>(out INT)
42 Set $1 to a random integer between C<[-2^31, 2^31)> .
46 inline op rand(out INT) {
47 $1 = Parrot_int_rand(0);
50 =item B<rand>(out NUM, in NUM)
52 Set $1 to a random floating point number between 0 and and $2, inclusive.
56 inline op rand(out NUM, in NUM) {
57 $1 = $2 * Parrot_float_rand(0);
60 =item B<rand>(out INT, in INT)
62 Set $1 to a integer between 0 and and $2, inclusive.
66 inline op rand(out INT, in INT) {
67 $1 = Parrot_range_rand(0, $2, 0);
70 =item B<rand>(out NUM, in NUM, in NUM)
72 Set $1 to a random floating point number between $2 and and $3, inclusive.
76 inline op rand(out NUM, in NUM, in NUM) {
77 $1 = $2 + ($3 - $2) * Parrot_float_rand(0);
80 =item B<srand>(in NUM)
82 Set the random number seed to $1. $1 is casted to an INTVAL.
86 inline op srand(in NUM) {
87 Parrot_srand((INTVAL)$1);
90 =item B<srand>(in INT)
92 Set the random number seed to $1.
96 inline op srand(in INT) {
97 Parrot_srand((INTVAL)$1);
100 =item B<rand>(out INT, in INT, in INT)
102 Set $1 to a integer between $2 and and $3, inclusive.
106 inline op rand(out INT, in INT, in INT) {
107 $1 = Parrot_range_rand($2, $3, 0);
114 Copyright (C) 2001-2009, Parrot Foundation.
118 This program is free software. It is subject to the same license
119 as the Parrot interpreter itself.
126 * c-file-style: "parrot"
128 * vim: expandtab shiftwidth=4: