A set of symbol and keywords can be used as infix operators Nim supports operator overloading.
Those symbols are:
= + - * / < > @ $ ~ & % | ! ? ^ . : \
The keyword operators are
and or not xor shl shr div mod in notin is isnot of as
- bitwise and, or, flip, xor are denoted
xorinstead of using a symbol
- shift left and right are
- division and modulo are
mod is defined as the mathematical remainder, like C. With signed integers
a mod b has the same sign as
shr of a signed integer will not preserve the sign bit.
ashr can be used for arithmetic right shift.
This distinction was introduced recently and may lead to subtle bugs,
ashr relies on the C compiler actually lowering
>> to SAR for signed integer.
This is specified for GCC and Clang (https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation)
but implementation defined in general.
Operator precedence is specified described in the manual:
Nim system exports additional operators with a
Those cast the signed integer operand to unsigned and cast the result back to signed.
This is intended to use with the ByteAddress type for pointer arithmetic