On Friday 24 October 2008 23:47:24 Keith Wright wrote:
> If by "consistent order" you mean that it is an
> extension of the usual order on the real numbers,
> then you lose again, because (< -2 -1) but (<? -1 -2),
> because (magnitude x) is not order preserving on
> the reals.
*sign* lost the sign *mumble*
My new sign
[0] Remember [1]
[1] Write unit tests first
[2] Don't post code until you do [1]
I apologize to the list for posting broken code and for not following the
above.
No excuse. Back to cleaning out the gutters.
-KenD
;;============================
The following <? predicate orders all Scheme numbers including complex numbers
based on polar coordinates.
;;============================
(library (mumble less)
(export <?)
(import (rnrs))
(define (<? a b)
(assert (number? a))
(assert (number? b))
(let ( [a^ ((sign a) (magnitude a))]
[b^ ((sign b) (magnitude b))]
)
(or (< a^ b^)
(and (= a^ b^)
(< (angle a) (angle b))))
) )
(define (sign num) (if (< (real-part num) 0) - +))
)
(import (rnrs)
(xitomatl srfi lightweight-testing)
(mumble less)
)
(check (<? -2 -1) => #t)
(check (<? 1/3 3+2i) => #t)
(check (<? 1/3 3-2i) => #t)
(check (<? 1/3 -3-2i) => #f)
(check (<? 1/3 -3+2i) => #f)
(check (<? 32 +14i) => #f)
(check (<? +14i 32) => #t)
(check (<? -3 +2.5i) => #t)
(check (<? -4 -3-2i) => #t)
(check (<? -4 3-2i) => #t)
(check (<? -4 3+2i) => #t)
(check (<? -4 -3+2i) => #t)
(check (<? -3-2i 4) => #t)
(check (<? 3-2i 4) => #t)
(check (<? 3+2i 4) => #t)
(check (<? -3+2i 4) => #t)
(check (<? 3+4i 5) => #f)
(check (<? 4+3i 5) => #f)
(check (<? 3+4i 5.1) => #t)
(check (<? 4+3i 5.1) => #t)
(check (<? -5 -3+4i) => #f)
(check (<? -5 -4+3i) => #f)
(check (<? -5.1 -3+4i) => #t)
(check (<? -5.1 -4+3i) => #t)
(check (<? -5 -3-4i) => #f)
(check (<? -5 -4-3i) => #f)
(check (<? -5.1 -3-4i) => #t)
(check (<? -5.1 -4-3i) => #t)
(check (<? 3 5)=> #t)
(check (<? 3 -5)=> #f)
(check (<? 3 3)=> #f)
(check (<? 1/6 1/3) => #t)
(check-report)
;;; --- E O F --- ;;;
_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss