User guide
3.3. GLOBAL FUNCTIONS 55
within the cur re nt function or routine can be performed using the GOTO command, so
level and longjump are only needed for non local jumps.
obj := mkobj(upb,fns,a,b,c,d,e,f,g,h,i,j,k) CIN:y, POS:y, NAT:y
This function creates and initialises an object. It definition is as follows:
LET mkobj(upb, fns, a, b, c, d, e, f, g, h, i, j, k) = VALOF
{ LET obj = getvec(upb)
IF obj DO
{ !obj := fns
InitObj#(obj, @a) // Send the init message to the object
}
RESULTIS obj
}
As can be se e n, it allocates a vector for the fields of the object, i ni t i al i se s its
zeroth element t o point to the methods vector and calls the initialisation method that
is ex pected to be in element InitObj of fns. The result is a pointer to the initialised
fields vector. If it fails, i t returns zero. As can be seen the initialisation method receives
a vector of up to 11 initialisation arguments.
res := muldiv(a, b, c) CIN:y, POS:y, NAT:y
The result is the value obtained by dividing c into the double length pr oduct of a
and b, the remainder of this division is left in the global variable result2. The result
is undefined if it is too l ar ge to fit into a single length word or if c is zero. The result
is also undefined if any of a, b or c is the largest n egat i ve int e ger .
This version of muldiv is defined in the hand written Ci ntco d e library syslib and
invokes the MDIV Cintcode instructi on which is implemented efficiently. The older ver-
sion is invoked by sys(Sys
muldiv,a,b,c) and uses binary long division implemented
in C. Both versions ar e believed to produce identical results except possibly when c=0.
As an example, the fun ct i on defined below calculates the cosine of the angle between
two unit vectors in three dimensions using scaled integers to represent numbers with 6
digits after the decimal point.
MANIFEST { Unit=1000000 } // Scaling factor for numbers of the
// form ddd.dddddd
FUN inprod(v, w) = muldiv(v!0, w!0, Unit) +
muldiv(v!1, w!1, Unit) +
muldiv(v!2, w!2, Unit)
Remember that scaled fixe d point values can be output conveniently usi ng writef
as in:
writef("%10.6d*n", 123_456789)
which will output the following:
123.456789