NXC
Version 1.2.1 r5
|
Values are the most primitive type of expressions.
More complicated expressions are formed from values using various operators.
Numerical constants in the NXT are represented as integers or floating point values. The type depends on the value of the constant. NXC internally uses 32 bit floating point math for constant expression evaluation. Numeric constants are written as either decimal (e.g. 123, 3.14) or hexadecimal (e.g. 0xABC). Presently, there is very little range checking on constants, so using a value larger than expected may produce unusual results.
Two special values are predefined: true and false. The value of false is zero (0), while the value of true is one (1). The same values hold for relational operators (e.g. <): when the relation is false the value is 0, otherwise the value is 1.
Values may be combined using operators. NXC operators are listed here in order of precedence from highest to lowest.
Operator | Description | Associativity | Restriction | Example |
---|---|---|---|---|
abs() | Absolute value | n/a | abs(x) | |
sign() | Sign of operand | n/a | sign(x) | |
++, – | Postfix increment/decrement | left | variables only | x++ |
++, – | Prefix increment/decrement | right | variables only | ++x |
- | Unary minus | right | -x | |
~ | Bitwise negation (unary) | right | ~123 | |
! | Logical negation | right | !x | |
*, /, % | Multiplication, division, modulus | left | x * y | |
+, - | Addition, subtraction | left | x + y | |
<<, >> | Bitwise shift left and right | left | x << 4 | |
<, >, <=, >= | relational operators | left | x < y | |
==, != | equal to, not equal to | left | x == 1 | |
& | Bitwise AND | left | x & y | |
^ | Bitwise exclusive OR | left | x ^ y | |
| | Bitwise inclusive OR | left | x | y | |
&& | Logical AND | left | x && y | |
|| | Logical OR | left | x || y | |
?: | Ternary conditional value | right | x==1 ? y : z |
Where needed, parentheses are used to change the order of evaluation: