2.1.3 Numeric Operators

This the list of numeric operators in Haxe, grouped by descending priority.

Unary
OperatorOperationOperand 1Operand 2Return
~bitwise negationIntN/AInt
+plusFloat/IntN/AFloat/Int
-minusFloat/IntN/AFloat/Int
++incrementFloat/IntN/AFloat/Int
--decrementFloat/IntN/AFloat/Int
Arithmetic
OperatorOperationOperand 1Operand 2Return
%moduloFloat/IntFloat/IntFloat/Int
OperatorOperationOperand 1Operand 2Return
*multiplicationFloat/IntFloat/IntFloat/Int
/divisionFloat/IntFloat/IntFloat
OperatorOperationOperand 1Operand 2Return
+additionFloat/IntFloat/IntFloat/Int
-subtractionFloat/IntFloat/IntFloat/Int

About Float/Int return type: If one of the operands is of type Float, the resulting expression will also be of type Float, otherwise the type will be Int.

Bitwise
OperatorOperationOperand 1Operand 2Return
<<shift leftIntIntInt
>>shift rightIntIntInt
>>>unsigned shift rightIntIntInt
OperatorOperationOperand 1Operand 2Return
&bitwise andIntIntInt
|bitwise orIntIntInt
^bitwise xorIntIntInt
Comparison
OperatorOperationOperand 1Operand 2Return
==equalFloat/IntFloat/IntBool
!=not equalFloat/IntFloat/IntBool
<less thanFloat/IntFloat/IntBool
<=less than or equalFloat/IntFloat/IntBool
>greater thanFloat/IntFloat/IntBool
>=great than or equalFloat/IntFloat/IntBool
Equality

For enums:

  • Enum without parameters Are always represent the same value, so MyEnum.A == MyEnum.A.
  • Enum with parameters Can be compared with a.equals(b) (which is a short for Type.enumEquals()).

Dynamic: Comparison involving at least one Dynamic value is unspecifed and platform-specific.

Differences with other languages

Haxe precedence differ from other languages for the following cases:

  • % have lower precedence than * and / whereas in C these three have the same
  • |, & and ^ have the same precedence in Haxe, so they will be always grouped from left-to-right, whereas in C & have lower precedence than ^ which itself have lower precedence than |
  • |, & and ^ also have lower precedence than == and != in Haxe

Take the Haxe Survey!