Operators
List of all supported operators ordered by precedence.
Precedence affects the order how things are evaluated. The most basic example is a * b + c * d in which case you want the parser to interpret it like (a * b) + (c * d) and not like a * (b + (c * d)) (or some other variation).
Prefix: -, !
-prefix (e.g.-a) is a negation, which can be done onint,float,ksp::math::Vec2,ksp::math::Vec3!prefix (e.g.!condition) is a logical not, which can be done onbool
Power of (version >= 0.4.3)
**(e.g.a ** b) raisesato the power ofbint ** intresultintfloat ** floatresultfloat
Multiplication / division / modulo: *, /, %
*(e.g.a * b) multiplies two values, which is allowed forint * intresultintfloat * floatresultfloatfloat * ksp::math::Vec2resultksp::math::Vec2ksp::math::Vec2 * floatresultksp::math::Vec2ksp::math::Vec2 * ksp::math::Vec2resultfloat(vector dot product)float * ksp::math::Vec3resultksp::math::Vec3ksp::math::Vec3 * floatresultksp::math::Vec3ksp::math::Vec3 * ksp::math::Vec3resultfloat(vector dot product)Note: You can not multiply
intwithfloat, one of them as to be converted via.to_floator.to_int
/(e.g.a / b) divides first value by the second value, which is allowed forint / intresultint(Note: result will be truncated1 / 2is0)float / floatresultfloatksp::math::Vec2 / floatresultksp::math::Vec2ksp::math::Vec3 / floatresultksp::math::Vec3Note: You can not device
intwithfloator vice versa, one of them as to be converted via.to_floator.to_int
%(e.g.a % b) gets the remainder of the division of the first value by the second value, which can on, which is allowed forint % intresultintfloat % floatresultfloat
Addition / subtraction: +, -
+(e.g.a + b) adds two values, which is allowed forint + intresultintfloat + floatresultfloatstring + stringresultstring(concatenate two strings)ksp::math::Vec2 + ksp::math::Vec2resultksp::math::Vec2ksp::math::Vec3 + ksp::math::Vec3resultksp::math::Vec3Note: You can not add
intwithfloat, one of them as to be converted via.to_floator.to_int
-(e.g.a - b) subtracts the second value from the first, which is allowed forint - intresultintfloat - floatresultfloatksp::math::Vec2 - ksp::math::Vec2resultksp::math::Vec2ksp::math::Vec3 - ksp::math::Vec3resultksp::math::Vec3Note: You can not subtract
intwithfloat, one of them as to be converted via.to_floator.to_int
Bit-And / Bit-Or / Bit-Xor: &, |, ^
Create range: .., ...
Ranges can be created from two int value.
a .. bcreates a range fromatobexclusively (i.e.>= aand< b)a ... bcreates a range fromatobinclusively (i.e.>= aand<= b)
Comparison: ==, !=, <, <=, >, >=
The result of a comparison is always a
bool==and!=check the equality resp. not-equality of two values. The following types can be comparedboolwithboolintwithintfloatwithfloatstringwithstringksp::math::Vec2withksp::math::Vec2ksp::math::Vec3withksp::math::Vec3
<,<=,>,>=compare the order of two values, i.e. less than, less of equal, greater than, greater or equal. The following types can be comparedintwithintfloatwithfloatstringwithstring(standard string ordering)
Boolean and / Boolean or: &&, ||
&&combines twoboolwith an and||combines twoboolwith an or
Note that this operator short-circuits if the result is already determined by the first boolean. E.g. if you have a boolean value and a function returning a boolean:
fn some_func() -> bool = { ... }
let a : bool
then a && some_func() will not invoke some_func if a is false. Correspondingly a || some_func() will not invoke some_func if a is `true.