Mathematical Expressions
Mathematical operators in steve function almost exactly the same as they do in C, although there are some additions to account for vector and matrix types.
The following binary operators are valid for int and double types (the descriptions refer to x and y, as though they were used in an
expression: x ):
operator y
-
+, addition -
-, subtraction -
*, multiplication -
/, division -
%, modulus (the remainder of x when divided by y) -
^, power (x raised to the power of y)
Their functions should be self-explanatory, with the possible exception of modulus, which cannot be used with double types in C. When used with doubles, the result is calculated using the ANSI C
fmod() function.
The following operators are valid for use with two vectors:
-
+, vector addition -
-, vector subtraction
The following operators are valid for a vector and a double (although an int is automatically promoted to a double in this case):
-
*, vector multiplied by scalar -
/, vector divided by scalar
As in many languages, parentheses are used to group expressions when the default order of operations does not compute the desired result:
# this is the default order, but we can make it explicit with parens x = x + (4 / y). # computes 4 / y first... # this is NOT the default order -- we need to force it x = (x + 4) / y. # computes x + 4 first
Mathematical expressions are often used in conjunction with assignments in order to modify the value of a variable. A few examples of using mathematical expressions in conjunction with assignments follow:
x = x + 4.
y = (1, 2, 3) / x. # assumes x is an int or double
z = z + x^2.
