Div
Operator
Divides one number by a second number, if possible. But if division is not possible, the result is zero (default) or a value that you supply.
Syntax
Operator construct
expression_1 Div expression_2
Function construct
Div ( expression_1, expression_2 [ , expression_3 ] )
Parts
expression_1
- Mandatory numeric expression, also known as the numerator.
expression_2
- Mandatory numeric expression, also known as the denominator.
expression_3
- Optional numeric expression that becomes the result if division is not possible. It is available only in the function construct. If not supplied, the default is zero.
Instructions
Most of the time, when you divide a number by zero, it is accidental. But there are times when you cannot prevent it.
For example, physics calculations frequently have distances in the denominator. This can cause problems every time the distance goes to zero. But many times these calculations have no problems when the result of division by zero is zero.
If you know that division by zero does not cause a problem, you can use Div
as an alternative to «/
».
But if you are not sure, Div
can cause problems that are not easy to find.
Operator construct
With the operator construct, you write the keyword Div
between two numeric expressions.
It tries to divide expression_1
by expression_2
.
If expression_2
is not zero, Div
operates the same as «/
».
But if expression_2
is zero, the result is zero.
Function construct
With the function construct, you first write Div
.
Then between parentheses (( )
, you write two or three expressions, with a comma (,
) between each.
It tries to divide expression_1
by expression_2
.
If expression_2
is not zero, Div()
operates the same as «/
», but with a higher precedence.
If expression_2
is zero and you did not supply expression_3
, the result is zero.
But if you supplied expression_3
, its value becomes the result.
All expressions must have the same data type.
Data types
If the two expressions are integers smaller than Int64
, they automatically convert to Int64
.
Then the result is also Int64
.
But if one of the expressions is Int128
, the smaller one automatically converts to Int128
.
Then the result is also Int128
.
If one or two of the expressions are floating-point numbers smaller than Real64
, they automatically convert to Real64
.
Then the result is also Real64
.
But if one of the expressions is Real128
, the smaller one automatically converts to Real128
.
Then the result is also Real128
.
Examples
TODO