Extends =~ to complex numbers

This is a (variation of a) fix from David van Horn.

Closes PR 11547.
This commit is contained in:
Mike Sperber 2010-12-26 09:03:10 +01:00
parent 7282e19178
commit d5c58d9f82
2 changed files with 7 additions and 7 deletions

View File

@ -484,10 +484,10 @@
(eqv? (any any -> boolean) (eqv? (any any -> boolean)
"to determine whether two values are equivalent from the" "to determine whether two values are equivalent from the"
" perspective of all functions that can be applied to it (extensional)") " perspective of all functions that can be applied to it (extensional)")
((beginner-=~ =~) (real real non-negative-real -> boolean) ((beginner-=~ =~) (number number non-negative-real -> boolean)
"to check whether two real numbers are within some amount (the third argument) of either other") "to check whether two numbers are within some amount (the third argument) of either other")
((beginner-equal~? equal~?) (any any non-negative-real -> boolean) ((beginner-equal~? equal~?) (any any non-negative-real -> boolean)
"to compare like equal? on the first two arguments, except using =~ in the case of real numbers") "to compare like equal? on the first two arguments, except using =~ in the case of numbers")
(eof eof (eof eof
"the end-of-file value") "the end-of-file value")
(eof-object? (any -> boolean) (eof-object? (any -> boolean)

View File

@ -276,8 +276,8 @@ namespace.
(current-continuation-marks))))]) (current-continuation-marks))))])
(let ? ([a x][b y]) (let ? ([a x][b y])
(cond (cond
[(real? a) [(number? a)
(and (real? b) (and (number? b)
(beginner-=~ a b epsilon))] (beginner-=~ a b epsilon))]
[(procedure? a) [(procedure? a)
(fail "first argument of equality cannot be a procedure, given ~e" a)] (fail "first argument of equality cannot be a procedure, given ~e" a)]
@ -318,8 +318,8 @@ namespace.
(define-teach beginner =~ (define-teach beginner =~
(lambda (a b c) (lambda (a b c)
(check-three a b c '=~ real? 'real real? 'real positive-real? 'non-negative-real) (check-three a b c '=~ number? 'number number? 'number positive-real? 'non-negative-real)
(<= (- a c) b (+ a c)))) (<= (magnitude (- a b)) c)))
(define-teach beginner equal~? (define-teach beginner equal~?
(lambda (a b c) (lambda (a b c)