Sheerpower supports the following mathematical operators:
+ addition
- subtraction
* multiplication
/ division
^ exponentiation
++ increment a variable's value.. For example: counter++
Sheerpower supports the following logical operators:
< less than X is less than Y
<= less than or equal to X is less than or equal to Y
= equals X is equal to Y
> greater than X is greater than Y
>= greater than or equal to X is greater than or equal to Y
<> not equal to X is not equal to Y
!= not equal to X is not equal to Y
NOT NOT X TRUE if X is false
AND X AND Y TRUE if X and Y are both true
OR X OR Y TRUE if either X or Y are true
XOR X XOR Y TRUE if X is true, or if Y is true, FALSE if X and Y are both true or both false
IMP X IMP Y TRUE if X is true and Y is false
EQV X EQV Y TRUE if X and Y are true, or
TRUE if X and Y are false, FALSE otherwise
Sheerpower Logical Operators
AND Operator
The AND operator returns true if both operands are true.
a = true
b = false
print a and b // Returns: false
OR Operator
The OR operator returns true if at least one operand is true.
a = true
b = false
print a or b // Returns: true
NOT Operator
The NOT operator returns true if the operand is false.
a = false
print not a // Returns: true
XOR Operator
The XOR operator returns true if only one of the operands is true.
a = true
b = false
print a xor b // Returns: true
IMP Operator (Implication)
The IMP operator returns false if the first operand is true and the second operand is false, otherwise true.
a = true
b = false
print a imp b // Returns: false
EQV Operator (Equivalence)
The EQV operator returns true if both operands are either true or false.
a = true
b = true
print a eqv b // Returns: true
In addition there are a lot of built-in mathematical functions.
See
common math functions
and
transcendental functions for details.
Note: When calling a built-in function without any parameters, you must omit the () that follows
the function name.
print rnd(100) // a random number from 1 to 100
print rnd // a random fraction
Order of Evaluation
Sheerpower always evaluates expressions in parentheses first. Parentheses,
( ), can be used to
change the order of any of the following operations. If parentheses are nested,
Sheerpower evaluates them from the inside out. For example:
Z - (X / (Y+AMOUNT))
Sheerpower evaluates the expression
Y + AMOUNT first. Next, it
divides the X by that result.
Finally, it
subtracts the entire expression from Z.
- Sheerpower performs functions second.
- Sheerpower performs exponentiation.
- Sheerpower performs multiplication and division.
- Sheerpower performs addition and subtraction.
- Sheerpower performs relational operations from left to right.
(The relational operators are: =, <, >, <=, >= and <>.) The only exception is the assignment of the
result. The result is always assigned last.
Sheerpower performs logical operations in the following order:
NOT
AND
OR
XOR
IMP
EQV
For clarity,
Parentheses can be used around every set of operations. This makes it easy to
pick out the beginning and end of an operation, and will make absolutely
clear what is intended without depending on the order of precedence of
operators.