Version 1 (modified by cowan, 5 years ago) (diff) |
---|

This is a WG2 proposal to extend Scheme's exact number system with exact equivalents of `+inf.0`, `-inf.0`, `+nan.0`, and `-0.0`.

## Proposal

Implementations may distinguish special exact numbers called *exact positive infinity, exact negative infinity, exact NaN*, and *exact negative zero*.

Exact positive infinity is regarded as an real (but not rational) number written `1/0` that represents a value greater than the numbers represented by all rational numbers. Exact negative infinity is regarded as an exact real (but not rational) number written `-1/0` that represents a value less than the numbers represented by all rational numbers. Forms such as `2/0` and `-3/0` are accepted on input but are not produced on output.

Adding or multiplying an exact infinite value by any finite real value results in an appropriately signed exact infinity; however, the sum of positive and negative exact infinities is an exact NaN. Exact positive infinity is the reciprocal of exact zero, and exact negative infinity is the reciprocal of exact negative zero.

An exact NaN is regarded as an inexact real (but not rational) number written `0/0` that is so indeterminate that it might represent any real value, including positive or negative infinity.

An exact NaN always compares false to any number, including a NaN. An exact arithmetic operation where one operand is an exact NaN returns an exact NaN, unless the implementation can prove that the result would be the same if the exact NaN were replaced by any rational number. Dividing exact zero by exact zero results in exact NaN.

Exact negative zero is an inexact real value written `-0/1` and is normally distinct (in the sense of `eqv?`) from `0`. However, a Scheme implementation that implements this proposal is *not* required to distinguish exact negative zero. Forms such as `-0/4` are accepted on input but are not produced on output.

The negation of exact negative zero is ordinary exact zero and vice versa. This implies that the sum of two or more exact negative zeros is negative, and the result of subtracting (positive) exact zero from an exact negative zero is likewise negative. However, numerical comparisons treat exact negative zero as equal to zero.

Note that both the real and the imaginary parts of an exact complex number can be exact infinities, NaNs, or negative zero.

## Implementations

Kawa Scheme implements this proposal, but does not support exact negative zero.