Specifications

3.6 Working with numbers 33
SECTION 3.6
Working with numbers
Arithmetic objects
Objects that operate on o rdinary numbers to provide basic maths functions are
summarised in Tbl. 3.24 All have hot left and cold rig ht inlets and all take one
argument that initialises the value otherwise received on the right inlet. Note
the difference between arithmetic division with
/
and the
div
object. The
modulo o perator gives the remainder of dividing the left number by the right.
Object Function
+
Add two floating point numbers
-
Subtract number on right inlet from number on left inlet
/
Divide lefthand number by number on right inlet
*
Multiply two floating point numbers
div
Integer divide, how many times the number on the right
inlet divides exactly into the number on the left inlet
mod
Mo dulo, the smallest remainder of dividing the left num-
ber into any integer multiple of the right number
fig 3.24: Table of message arithmetic operators
Tr igonometric maths objects
A summary of higher maths functions is given in Tbl. 3.25.
Random numbers
A useful ability is to make random numbers. The
random
object gives integers
over the range given by its argument including zero, so
random 10
gives 10 possible
values from 0 to 9.
Arithmetic example
random 100 random 100 random 100
+
96 12 88
trigger bang bang bang
+
/ 3
65.333
fig 3.26: Mean of three random
floats
An example is given in Fig. 3.26 to show cor-
rect ordering in a patch to calculate the mean
of three random numbers. We don’t have to
make every inlet hot, just ensur e that every-
thing arrives in the correct sequence by trig-
gering the
random
objects properly. The first
random
(on the right) supplies the cold inlet of
the lower
+
, the middle one to the cold inlet
of the upper
+
. When the nal (left)
random
is generated it pa sses to the hot inlet of the
first
+
, which computes the sum and passes it to the second
+
hot inlet.
Finally we divide by 3 to get the mean value.