next up previous contents index
Next: Math Functions Up: Plots, Vectors and Expressions Previous: Vector Expressions   Contents   Index


Operators in Expressions

The operations available in vector expressions are listed below. They all take two operands, except for unary minus and logical negation.

addition operator: +
Add the two operands.

subtraction amd negation operator: -
Evaluates to the first argument minus the second, and also may be used as unary minus.

multiply operator: *
Multiply the two operands.

divide operator: /
The first operand divided by the second.

modulo operator: %
This operates in the manner of the C fmod function, returning the remainder. That is, for x% y, the value of x- i* y is returned for some integer i such that the result has the same sign of x and magnitude less than the magnitude of y. An error is indicated if y is zero. If x or y is complex, the magnitudes are used in the division.

power operator: ^ or **
Evaluates to the first operand raised to the power of the second.

and operator: & or && or and
Evaluates to 1 if both operands are non-zero, 0 otherwise.

or operator: | or || or or
Evaluates to 1 if either of the two operands is nonzero, 0 otherwise.

not operator: ~ or ! or not
Evaluates to 1 if the operand is 0, 0 otherwise.

greater-than operator: > or gt
Evaluates to 1 if the first operand is greater than the second, 0 otherwise.

greater-than-or-equal operator: > = or ge
Evaluates to 1 if the first operand is greater than or equal to the second, 0 otherwise.

less-than operator: < or lt
Evaluates to 1 if the first argument is less than the second, 0 otherwise.

less-than-or-equal operator: < = or le
Evaluates to 1 if the first argument is less than or equal to the second, 0 otherwise.

not-equal operator: < > or ! = or ne
Evaluates to 1 if the two operands are not equal, 0 otherwise.

equal operator: = or = = or eq
Evaluates to 1 if both operands are equal, 0 otherwise.

ternary conditional operator: expr ? expr1 : expr2
If expr evaluates nonzeor (true), the result of the evaluation of expr1 is returned. Otherwise, the result of evaluating expr2 is returned. For Example:
let v = (a == 2) ? v(1) : v(2)
This will set v to v(1) if vector a is equal to 2, v to v(2) otherwise.

comma operator: ,
The notation a,b refers to the complex number with real part a and imaginary part b. Such a construction may not be used in the argument list to a macro function, however, since commas are used to separate the arguments and parentheses may be ignored. The expression a + j(b) is equivalent. The comma does not behave as an operation (return a value) as it does in C.

The logical operations are & (and), | (or), ~ (not), and their synonyms. A nonzero operand is considered ``true''. The relational operations are < , > , < = , > = , = , and < > (not equal), and their synonyms. If used in an algebraic expression they work like they would in C, producing values of 0 or 1. The synonyms are useful when < and > might be confused with IO redirection (which is almost always).

expression terminator: ;
The expression parser will terminate an expression at a semicolon. This can be used to enforce tokenization of expression lists, however it will also terminate command parsing if surrounded by white space.

Vectors may be indexed by value[index] or value[low,high].

The first notation refers to the index'th element of value. The second notation refers to all of the elements of value which fall between the high'th and the low'th element, inclusive. If high is less than low, the order of the elements in the result is reversed. Note that a complex index will have the same effect as using the real part for the lower value and the imaginary part for the upper, since this is the way the parser reads this expression. Multi-dimensional vectors are referenced as Vec[indN][indN-1]...[ind0], where each of the indI can be a range, or single value. The range must be within the vector's spanning space. If fewer than the vector's dimensions are specified, the resulting object is a sub-dimensional vector.

Finally, there is the ran operator: value1[[value2]] or value[[low,high]].

The first notation refers to all the elements of value1 for which the element of the corresponding scale equals value2. The second notation refers to all of the elements of value for which the corresponding elements of the scale fall between high and low, inclusive. If high is less than low, the order of the elements in the result is reversed.


next up previous contents index
Next: Math Functions Up: Plots, Vectors and Expressions Previous: Vector Expressions   Contents   Index
Stephen R. Whiteley 2017-10-02