We've already seen the standard arithmetic operators.
The addition, +, and subtraction, -, operators use full 32-bit integers, but, for efficiency, multiplication, *, and division, /, use restricted values.
You can use * only to multiply 16-bit integers, and the result will be a 32-bit integer.
Similarly, you can use / only to divide a 32-bit integer by a 16-bit integer, and the result will be a 16-bit integer.
The restrictions do not affect most calculations, but if you really need to use all 32-bit integers (and you can cope with overflows, etc.) you can use the Mul and Div functions.
Mul(a,b) corresponds to a*b, and Div(a,b) corresponds to a/b.
We've also met the logic operators AND and OR, which we know are really bit-wise operators.
You can also use the functions And and Or to do exactly the same as AND and OR (respectively).
So, for instance, And(a,b) is the same as a AND b.
The reason for these functions is because there are Not and Eor (bit-wise) functions, too (and there aren't operators for these).
Not(a) swaps one and zero bits, so, for instance, Not(TRUE) is FALSE and Not(FALSE) is TRUE.
Eor(a,b) is the exclusive version of Or and does almost the same, except that Eor(1,1) is 0 whereas Or(1,1) is 1 (and this extends to all the bits).
So, basically, Eor tells you which bits are different, or, logically, if the truth values are different.
Therefore, Eor(TRUE,TRUE) is FALSE and Eor(TRUE,FALSE) is TRUE.
There's a collection of other functions related to maths, logic or numbers in general:
Abs(expression)
Abs(9) is 9, and Abs(-9) is also 9.
Sign(expression)
Even(expression)
TRUE if expression represents an even number, and FALSE otherwise.
Obviously, a number is either odd or even!
Odd(expression)
TRUE if expression represents an odd number, and FALSE otherwise.
Max(exp1, exp2)
Min(exp1, exp2)
Bounds(exp, minexp, maxexp)
The following code fragments are equivalent:
y:=Bounds(x, min, max) y:=IF x<min THEN min ELSE IF x>max THEN max ELSE x
Mod(exp1,exp2)
a to 5 (since
26=(7*3)+5),
b to 3, c to -5 and d to -3.
It is important to notice that if exp1 is negative then the modulus will also be negative.
This is because of the way integer division works: it simply discards fractional parts rather rounding.
a,b:=Mod(26,7) c,d:=Mod(-26,7)
Rnd(expression)
Rnd for the first time in your program you should call it with a negative number.
This decides the starting point for the pseudo-random numbers.
RndQ(expression)
Rnd, but returns values in the 32-bit range, not a specified range.
The seed value is used to select different sequences of pseudo-random numbers, and the first call to RndQ should use a large value for the seed.
Shl(exp1,exp2)
Shl(%0001110,2) is %0111000 and Shl(%0001011,3) is %1011000.
Shifting a number one bit to the left is generally the same as multiplying it by two (although this isn't true when you shift large positive or large negative values).
(The new bits shifted in at the right are always zeroes.)
Shr(exp1,exp2)
Shr(%0001110,2) is %0000011 and Shr(%1011010,3) is %0001011.
For positive exp1, shifting one bit to the right is the same as dividing by two.
(The new bits shifted in at the left are zeroes if exp1 is positive, and ones otherwise, hence preserving the sign of the expression.)
Long(addr), Int(addr), Char(addr)
LONG, INT or CHAR value at the address addr.
These functions should be used only when setting up a pointer and dereferencing it in the normal way would make your program cluttered and less readable.
Use of functions like these is often called peeking memory (especially in dialects of the BASIC language).
PutLong(addr,exp), PutInt(addr,exp), PutChar(addr,exp)
LONG, INT or CHAR value represented by exp to the address addr.
Again, these functions should be used only when really necessary.
Use of functions like these is often called poking memory.
Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.