Library functions: operations on integer and floating point numbers |
The Proteus language does not include any operator; even common operations are expressed by using functions, which in turn determine how their parameters should be evaluated.
The functions in this category are divided in the following three classes:
The names of the functions are similar to their 'C' counterparts (whenever possibile), or to the Assembly opcodes. The functions that translate binary operators on numbers always start with the letter N (e.g. NAND, NOR, etc.), to distinguish them from their logical counterparts; e.g.:
- logical operator: AND(1, 2) = 1 (both values are not 0)
- binary operator: NAND(1, 2) = 0
If one parameter is prefixed by the character "@", the function stores there the result.
DIV([@]n1, [@]n2[, n3..])
integer division (n1 / n2)[/ n3..]
MOD([@]n1, [@]n2[, n3..])
modulus (remainder of the integer division of n1 by n2 [by n3..])
FACT([@]n)
factorial of n
NAND([@]n1, [@]n2[, n3..])
same as '&' in 'C': binary AND of the specified numbers; e.g. NAND(1, 3) = 1
NOR([@]n1, [@]n2[, n3..])
same as '|' in 'C': binary OR of the specified numbers; e.g. NOR(1, 3) = 1
NXOR([@]n1, [@]n2[, n3..])
same as '^' in 'C': binary XOR of the specified numbers; e.g. NXOR(1, 3) = 2
NNOT([@]n)
same as '~' in 'C': binary NOT (complement) of n
SHIFTLT([@]n, nNumBits)
left shifts the integer number n by nNumBits
SHIFTRT([@]n, nNumBits)
right shifts the integer number n by nNumBits
BITGET([@]n, nOffset)
returns the bit nOffset of the integer number n; the returned value is always 0 or 1; if nOffset is invalid, returns 0
BITSET([@]n, nOffset, nBit)
sets the bit at nOffset in n to nBit (0 or 1)
RANDOM(nMax) RANDOM(nMin, nMax)
returns a random integer number in the range [0, nMax - 1] if a single parameter is specified, or an integer value in the range [nMin, nMax] if two parameters are specified. To obtain a random number between 0 and the greatest integer number, use a negative value as the only parameter (e.g. -1); to obtain a negative or positive random number, whose absolute value is in the range [0, (greatest positive integer) / 2], use -1 both for nMin and nMax. If you want a meaningful result, the range |nMax - nMin| must always be lesser than the greatest positive integer.
RANDOMINIT(n)
reinitializes the random number generator by using the specified value. Proteus automatically initializes the random number generator with information from the execution environment when the interpreter begins executing, so it is not needed to explicitly invoke this function, unless the user needs to repeat a certain random number sequence. Whenever the user invoke the function STRRANDOM, the random number generator is re-initialized with the value passed as the third parameter.
BIN2S(n)
returns a string of '0' and '1' with the binary representation of n
S2BIN(c)
returns the number corresponding to the binary representation of c (string of '0' and '1'); if c is invalid, returns 0
FDIV([@]f1, [@]f2[, f3..])
floating point division of (f1 / f2)[/ f3..]
FMOD([@]f1, [@]f2[, f3..])
floating point modulus (remainder of the division n1 / n2 [/ n3..])
FRAC([@]f)
decimal part of f
EXP([@]f)
returns e^f
POW([@]f1, [@]f2[, f3..])
returns f1 ^ f2 [^ f3..]
SQRT([@]f)
returns the square root of f
SIN([@]f)
returns sin(f )
COS([@]f)
returns cos(f )
TAN([@]f)
returns tan(f )
ASIN([@]f)
returns arcsin(f )
ACOS([@]f)
returns arccos(f )
ATAN([@]f)
returns arctan(f )
LOG10([@]f)
returns log10(f )
LOG([@]f)
returns log(f )
CEIL([@]f)
returns the ceiling of f (minimum integer number which is >= f)
FLOOR([@]f)
returns the floor of f (maximum integer number whish is <= f)
HYP([@]f1, [@]f2)
returns the square root of f1^2 + f2^2
MUL([@]nf1, [@]nf2[, nf3..])
return nf1 * nf2 [* nf3..]
ADD([@]nf1, [@]nf2[, nf3..])
return nf1 + nf2 [+ nf3..]
SUB([@]nf1, [@]nf2[, nf3..])
returns nf1 - nf2 [- nf3..]
INC([@]nf)
returns nf + 1 (if nf is a variable, its value is modified only if passed by reference)
DEC([@]nf)
returns nf - 1 (if nf is a variable, its value is modified only if passed by reference)
INT([@]nf)
integral part (returns an integer number, or a floating point if the value is too large to be represented)
ABS([@]nf)
returns the absolute value of nf
NEG([@]n)
returns -nf
MIN([@]nf1, [@]nf2[, nf3..])
returns the minimum of the values specified
MAX([@]nf1, [@]nf2[, nf3..])
returns the maximum of the values specified
EQ(nf1, nf2)
returns a value different than 0 if and only if nf1 == nf2
NEQ(nf1, nf2)
returns a value different than 0 if and only if nf1 != nf2
LT(nf1, nf2)
returns a value different than 0 if and only if nf1 < nf2
LE(nf1, nf2)
returns a value different than 0 if and only if nf1 <= nf2
GT(nf1, nf2)
returns a value different than 0 if and only if nf1 > nf2
GE(nf1, nf2)
returns a value different than 0 if and only if nf1 >= nf2
Proteus promotes an integer number to a floating point whenever the result of an operation is out of the allowed range (e.g. when multiplying numbers).
Start of page | Next topic | Previous topic | Contents | Index |