Integer Division
From Xojo Documentation
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site! |
The \ operator is used to perform Integer division between two numbers.
Usage
result = expression1 \ expression2
Part | Type | Description |
---|---|---|
result | Integer | The Integer division of expression1 and expression2. |
expression1 | Number | Any numeric expression. |
expression2 | Number | Any numeric expression. |
Notes
Use this operator when you require division that does not consider the decimal portion of the expressions. The result may differ from systems that round the expressions prior to the division.
If expression1 and expression2 are not integers, they are coerced to Int32s. The result is an Integer. If you divide by zero, the result is undefined even if the numerator is also zero. The only expected behavior is the application will not crash. For that reason, you should always check to see whether the denominator is zero before using \.
When converting a floating point number to an Integer, there is always the chance of data loss. The same is true when a floating-point value holds a sentinel such as infinity or NaN. Integers do not reserve space for sentinel values, so that information is lost. Converting a floating-point number that represents a sentinel to an Integer yields undefined results.
Use the / operator for floating point division and the Mod operator to obtain the remainder of the division.
You can use Operator_IntegerDivide to define the \ operator for classes.
Sample Code
This code stores the result of a division of two numbers in a variable:
See Also
/, Mod operators; Operator_IntegerDivide function; Operator precedence