This SRFI is currently in withdrawn status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to
firstname.lastname@example.org. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.
With infinities added to the number system we find that division by zero "works". It lets initialization of variables precede bounds checks and gives flexibility in placement of those checks.
Actually this SRFI was inspired by SRFI-70 (inexact infinities). I once discussed exact infinities in SRFI-70 mail list with Aubrey Jaffer, but he didn't intend to include exact infinities in SRFI-70. So here I define them as another SRFI. For no ambiguity, in the rationale and specification part I will use #e1/0 for rational infinity and #i1/0 for inexact infinity. Since SRFI-70 is still in draft status, I think we should work together to make SRFI-70 and this SRFI to be compatible to each other. In the current specification part, I leave many "..." to indicate this part should be defined in SRFI-70, or, leave unchanged as in R5RS. Nearly all changes on R5RS are orthogonal to SRFI-70, with the only exception that I define infinite? instead of finite?.
Finally, I have to say that the semantics of infinities in SRFI-70 and this SRFI is different. According to SRFI-70:
"The interpretation of real infinities is that #i1/0 represents real numbers greater than can be encoded by finite inexacts in the implementation (> 179.76931348623158e306 for IEEE-754 64-bit flonums) and that #i-1/0 represents numbers less than can be encoded by finite inexacts in the implementation (< -179.76931348623158e306 for IEEE-754 64-bit flonums)."
The interpretation of rational infinities here is that they are exact, rational numbers with denominator 0.
Should there be a #e0/0?
SRFI-70 defines an optional #i0/0. Should I also define an (optional) #e0/0?
The exact rational operations of addition, subtraction, multiplication, and division, plus a variety of other useful operations (comparison, reading, writing) form a useful suite of routines and is defined in Scheme spec. The construction of these programs depends on the availability of arbitrary precision integer arithmetic.
This SRFI extend the rational numbers of R5RS by adding two rational infinities (#e1/0, #e-1/0). These infinities arise as the result of exact division by 0.
There are two rationales for adding exact infinity: aesthetic and utilitarian. Aesthetically, having exact infinites allows one level of calculation (exact division by 0) to be executed before bounds checking, just as SRFI-70 has inexact infinites to enable inexact division by 0. A Scheme with only inexact infinity but no exact infinity is also not aesthetically satisfied. Another rationale is utility. For example, interval arithmetic may need rational infinity.
Because there are both positive infinity and negative infinity, we are forced to have two zeroes: positive 0 and negative -0. Among other reasons for preferring it, this model is more suited to transcendental functions allowing one to describe branch cuts more specifically. (The idea "-0" comes from Richard J. Fateman, see the reference for details.)
For any operation that involves both exact (infinity) and inexact numbers, it is a common arithmetic that all exact numbers will first be coerced into inexact and then the computation continues. So in this SRFI I will not concern on inexact numbers.
(Based on R5RS. "..." means this part should be defined same as SRFI-70)
6.2.4 Syntax of numerical constants
Negative exact infinity is written "#e-1/0". Positive exact infinity is written "#e1/0" or "#e+1/0". The positive exact zero is written "0" or "+0". The negative exact zero is written "-0".
The reader is referred to section 1.3.3 Entry format for a summary of the naming conventions used to specify restrictions on the types of arguments to numerical routines.
The examples used in this section assume that any numerical constant written using an exact notation is indeed represented as an exact number. Some examples also assume that certain numerical constants written using an inexact notation can be represented without loss of accuracy; the inexact constants were chosen so that this is likely to be true in implementations that use flonums to represent inexact numbers.
If z is an inexact complex number, then `(real? z)' is true if and only if `(zero? (imag-part z))' is true. If x is an inexact real number, then `(integer? x)' is true if and only if
(and (not (infinite? x)) (= x (round x)))
(complex? 3+4i) ==> #t (complex? 3) ==> #t (real? 3) ==> #t (real? -2.5+0.0i) ==> #t (real? #e1e10) ==> #t (rational? 6/10) ==> #t (rational? 6/3) ==> #t (integer? 3+0i) ==> #t (integer? 3.0) ==> #t (integer? 8/4) ==> #t (complex? #e1/0) ==> #t (real? #e-1/0) ==> #t (rational? #e1/0) ==> #t (integer? #e-1/0) ==> #f
Note: The behavior of these type predicates on inexact numbers is unreliable,
sincebecause any inaccuracy may affect the result.
Note: In many implementations the
rational?procedure will be the same as
real?, and the
complex?procedure will be the same as
number?, but unusual implementations may be able to represent some irrational numbers exactly or may extend the number system to support some kind of non-complex numbers.
(exact? #e1/0) ==> #t
(= #e1/0 #e1/0) ==> #t (= #e-1/0 #e1/0) ==> #f (= #e-1/0 #e-1/0) ==> #t (= #i1/0 #e1/0) ==> #t (= #e-1/0 #i-1/0) ==> #t (= 0 -0) ==> #f
For any finite positive number x:
(< #e-1/0 -x -0 0 x 1/0)) ==> #t
These predicates are required to be transitive.
Note: The traditional implementations of these predicates in Lisp-like languages are not transitive.
Note: While it is not an error to compare inexact numbers using these predicates, the results may be unreliable because a small inaccuracy may affect the result; this is especially true of
zero?. When in doubt, consult a numerical analyst.
(positive? #e1/0) ==> #t (negative? #e-1/0) ==> #t (infinite? #e-1/0) ==> #t (infinite? #e0/0) ==> #t (positive? 0) ==> #f (negative? -0) ==> #f (zero? 0) ==> #t (zero? -0) ==> #t
(max 3 4) ==> 4 ; exact (max 3.9 4) ==> 4.0 ; inexact
For any finite exact number x, any finite inexact number y:
(max #e1/0 x) ==> #e1/0 (max #e1/0 y) ==> #i1/0
Note: If any argument is inexact, then the result will also be inexact (unless the procedure can prove that the inaccuracy is not large enough to affect the result, which is possible only in unusual implementations). If `min' or `max' is used to compare numbers of mixed exactness, and the numerical value of the result cannot be represented as an inexact number without loss of accuracy, then the procedure may report a violation of an implementation restriction.
(+ 3 4) ==> 7 (+ 3) ==> 3 (+) ==> 0 (+ #e1/0 #e1/0) ==> #e1/0 (+ #e1/0 #e-1/0) ==> #i0/0, or raise an error if the Scheme implementation doesn't support #i0/0 (+ 0 -0) ==> 0 (+ 0 0) ==> 0 (+ -0 -0) ==> -0 (* 4) ==> 4 (*) ==> 1 (* 5 #e1/0) ==> #e1/0 (* -5 #e1/0) ==> #e-1/0 (* #e1/0 #e1/0) ==> #e1/0 (* #e1/0 #e-1/0) ==> #e-1/0 (* 0 #e1/0) ==> #i0/0, or raise an error if the Scheme implementation doesn't support #i0/0 (* 0 -0) ==> -0 (* 0 2) ==> 0 (* -0 -2) ==> 0 (* -0 2) ==> -0 (* 0 #e1/0) ==> #i0/0, or raise an error if the Scheme implementation doesn't support #i0/0
For any finite exact number z:
(+ #e1/0 z) ==> #e1/0 (+ #e-1/0 z) ==> #e-1/0
With two or more arguments:
(- z1 . z2) => (apply + z1
(map - z2))
(/ z1 . z2) => (apply * z1 (map / z2))
(- 0) ==> -0 (- -0) ==> 0 (- #e1/0) ==> #e-1/0 (- #-e1/0) ==> #e1/0 (- 3) ==> -3 (/ 0) ==> #e1/0 (/ -0) ==> #e-1/0 (/ #e1/0) ==> 0 (/ #e-1/0) ==> -0 (/ 3) ==> 1/3
(abs -7) ==> 7 (abs #e-1/0) ==> #e1/0 (abs -0) ==> 0
(numerator (/ 6 4)) ==> 3 (denominator (/ 6 4)) ==> 2 (denominator (exact->inexact (/ 6 4))) ==> 2.0 (numerator #e1/0) ==> 1 (numerator #e-1/0) ==> -1 (denominator #e1/0) ==> 0 (denominator #e-1/0) ==> 0
Rationale: `Round' rounds to even for consistency with the default rounding mode specified by the IEEE floating point standard.
Note: If the argument to one of these procedures is inexact, then the result will also be inexact. If an exact value is needed, the result should be passed to the `inexact->exact' procedure.
(floor -4.3) ==> -5.0 (ceiling -4.3) ==> -4.0 (truncate -4.3) ==> -4.0 (round -4.3) ==> -4.0 (floor 3.5) ==> 3.0 (ceiling 3.5) ==> 4.0 (truncate 3.5) ==> 3.0 (round 3.5) ==> 4.0 ; inexact (round 7/2) ==> 4 ; exact (round 7) ==> 7 (floor #e1/0) ==> #e1/0 (ceiling #e-1/0) ==> #e-1/0
`Inexact->exact' returns an exact representation of z. The value returned is the exact number that is numerically closest to the argument. If an inexact argument has no reasonably close exact equivalent, then a violation of an implementation restriction may be reported.
These procedures implement the natural one-to-one correspondence between
exact and inexact integers throughout an implementation-dependent range. See
(exact->inexact #e1/0) ==> #i1/0 (inexact->exact #i1/0) ==> #e1/0
(let ((number number) (radix radix)) (eqv? number (string->number (number->string number radix) radix)))
is true. It is an error if no possible result makes this expression true.
If z is inexact, the radix is 10, and the above expression can be satisfied by a result that contains a decimal point, then the result contains a decimal point and is expressed using the minimum number of digits (exclusive of exponent and trailing zeroes) needed to make the above expression true [howtoprint], [howtoread]; otherwise the format of the result is unspecified.
The result returned by `number->string' never contains an explicit radix prefix.
Note: The error case can occur only when z is not a complex number or is a complex number with a non-rational real or imaginary part.
Rationale: If z is an inexact number represented using flonums, and the radix is 10, then the above expression is normally satisfied by a result containing a decimal point. The unspecified case allows for infinities, NaNs, and non-flonum representations.
(string->number "100") ==> 100 (string->number "100" 16) ==> 256 (string->number "1e2") ==> 100.0 (string->number "15##") ==> 1500.0 (string->number "#e1/0") ==> #e1/0 (string->number "#e-1/0") ==> #e-1/0
Note: The domain of `string->number' may be restricted by implementations in the following ways. `String->number' is permitted to return #f whenever string contains an explicit radix prefix. If all numbers supported by an implementation are real, then `string->number' is permitted to return #f whenever string uses the polar or rectangular notations for complex numbers. If all numbers are integers, then `string->number' may return #f whenever the fractional notation is used. If all numbers are exact, then `string->number' may return #f whenever an exponent marker or explicit exactness prefix is used, or if a # appears in place of a digit. If all inexact numbers are integers, then `string->number' may return #f whenever a decimal point is used.
Here is my implementation, which is based on a Scheme implementation that supports arbitrary-big integer arithmetic as well as exact rational number computation. To avoid confusion with identifies in base-Scheme, all procedures defined in this SRFI (except infinite?) and prefixed with "my" or "my-". This reference implementation also requires SRFI-9, SRFI-13, SRFI-16, and SRFI-23.
> (exact->string (my-max (string->exact
(string->exact "-1"))) ;(max -1/2 -1)
> (exact->string (my+ (string->exact "-1/2")
> (exact->string (my* (string->exact "-0")
> (exact->string (my- (string->exact "0")
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.