Re: comparison operators and *typos
Aubrey Jaffer 21 Jun 2005 16:44 UTC
| Date: Mon, 20 Jun 2005 12:48:21 +0800
| From: "Chongkai Zhu" <xxxxxx@citiz.net>
|
| ======= At 2005-06-20, 10:06:21 Aubrey Jaffer wrote: =======
| >...
|
| (= -0 0) should be #f.
Then (eqv? -0 0) ==> #f; which will break much existing Scheme code
which tests for 0. The ZERO? procedure expects a number; one can test
whether an arbitrary object is 0 with (eqv? obj 0). Because of -0,
this test must be replaced by (and (number? obj) (<= -0 obj 0)).
Another example where -0 breaks existing code is:
(case val
((0) ...)
((1) ...)
(else ...))
will not match when VAL is -0.
(exact->string (my* -5 0)) ==> "-0". So -0 will occur often.
| > | procedure: numerator q
| > | procedure: denominator q
| > | These procedures return the numerator or denominator of their
| > | argument; the result is computed as if the argument was
| > | represented as a fraction in lowest terms. The denominator is
| > | always positive or zero. The denominator of 0 is defined to be
| > | 1.
(my-numerator |-0|) ==> 0
(my-denominator |-0|) ==> 1
(numerator 0) ==> 0
(denominator 0) ==> 1
If the NUMERATORs and DENOMINATORs of -0 and 0 are equal, then -0 and
0 must be the same number. But as you wrote, "(= -0 0) should be #f."
If (< -0 0), then -0 must be negative; but:
(my-negative? |-0|) ==> #f
If (< -0 0), then (- 0 -0) must be nonzero; but
(exact->string (my- 0 |-0|)) ==> "0"