Division by zero

Factor handbook » The language » Numbers » Arithmetic » Number protocol

Factor handbook » The language » Numbers » Arithmetic » Number protocol

Prev: | / ( x y -- z ) |

Next: | < ( x y -- ? ) |

Behavior of division operations when a denominator of zero is used depends on the data types in question, as well as the platform being used.

Floating point division only throws an error if the appropriate traps are enabled in the floating point environment. If traps are disabled, a Not-a-number value or an infinity is output, depending on whether the numerator is zero or non-zero.

Floating point traps are disabled by default and the math.floats.env vocabulary provides words to enable them. Floating point division is performed by /, /f or mod if at least one of the two inputs is a float. Floating point division is always performed by /f.

The behavior of integer division is hardware specific. On x86 processors, /i and mod raise an error if both inputs are integers and the denominator is zero. On PowerPC, integer division by zero yields a result of zero.

The / word, when given integer arguments, implements a much more expensive division algorithm which always yields an exact rational answer, and this word always tests for division by zero explicitly.

Floating point division only throws an error if the appropriate traps are enabled in the floating point environment. If traps are disabled, a Not-a-number value or an infinity is output, depending on whether the numerator is zero or non-zero.

Floating point traps are disabled by default and the math.floats.env vocabulary provides words to enable them. Floating point division is performed by /, /f or mod if at least one of the two inputs is a float. Floating point division is always performed by /f.

The behavior of integer division is hardware specific. On x86 processors, /i and mod raise an error if both inputs are integers and the denominator is zero. On PowerPC, integer division by zero yields a result of zero.

The / word, when given integer arguments, implements a much more expensive division algorithm which always yields an exact rational answer, and this word always tests for division by zero explicitly.

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.99 x86.64 (2173, heads/master-f3ee5c5979, Sep 18 2022 13:17:51)