Expressions

An expression combines values, operators, functions, constants, and variables. The evaluation of an expression is dependent on the precedence of the mathematical operators. You can overrule the precedence of the operators by enclosing part of your expression in parentheses.

For example, multiplication has a higher precedence than addition. Therefore, the expression 2+3*4 will result in 14 and not 20, because the multiplication of 3 and 4 is evaluated first. You can overrule the precedence with parentheses: (2+3)*4 will result in 20, because the part between parentheses is now evaluated first.

Back to top

Precedence

Precedence of math operators from highest to lowest:
( )
! ² ³
^
/, *, %
+, -
=, <>, <, >, <=, >=
And, Or, Xor, &, |, ||, >>, <<
Power (^) and factorial (!) have a higher precedence then minus. Therefore, if you enter -3^2 SpeQ will calculate -(3^2) = -9. If you want to calculate -3 squared, then you have to enter (-3)^2.

Back to top

Examples

'Examples of using expressions

2 + 3 * 4
       Ans = 14

(2 + 3) * 4
       Ans = 20

1.5 * 2 ^ 2
       Ans = 6

(1.5 * 2) ^ 2
       Ans = 9

5 * (2 + 3) + 2 ^ (2 + 2)
       Ans = 41

(5 + 2 / 3) ^ 2 / (1 + (4 / 2 + 1)) + 3 - 2
       Ans = 9.027777777

- 3 ^ 2
       Ans = -9

(-3) ^ 2
       Ans = 9
Back to top

See also

Constants, Defining Functions, Defining Variables, Functions Overview, Operators