Extends =~ to complex numbers
This is a (variation of a) fix from David van Horn. Closes PR 11547.
This commit is contained in:
parent
7282e19178
commit
d5c58d9f82
|
@ -484,10 +484,10 @@
|
|||
(eqv? (any any -> boolean)
|
||||
"to determine whether two values are equivalent from the"
|
||||
" perspective of all functions that can be applied to it (extensional)")
|
||||
((beginner-=~ =~) (real real non-negative-real -> boolean)
|
||||
"to check whether two real numbers are within some amount (the third argument) of either other")
|
||||
((beginner-=~ =~) (number number non-negative-real -> boolean)
|
||||
"to check whether two numbers are within some amount (the third argument) of either other")
|
||||
((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
|
||||
"the end-of-file value")
|
||||
(eof-object? (any -> boolean)
|
||||
|
|
|
@ -276,8 +276,8 @@ namespace.
|
|||
(current-continuation-marks))))])
|
||||
(let ? ([a x][b y])
|
||||
(cond
|
||||
[(real? a)
|
||||
(and (real? b)
|
||||
[(number? a)
|
||||
(and (number? b)
|
||||
(beginner-=~ a b epsilon))]
|
||||
[(procedure? a)
|
||||
(fail "first argument of equality cannot be a procedure, given ~e" a)]
|
||||
|
@ -318,8 +318,8 @@ namespace.
|
|||
|
||||
(define-teach beginner =~
|
||||
(lambda (a b c)
|
||||
(check-three a b c '=~ real? 'real real? 'real positive-real? 'non-negative-real)
|
||||
(<= (- a c) b (+ a c))))
|
||||
(check-three a b c '=~ number? 'number number? 'number positive-real? 'non-negative-real)
|
||||
(<= (magnitude (- a b)) c)))
|
||||
|
||||
(define-teach beginner equal~?
|
||||
(lambda (a b c)
|
||||
|
|
Loading…
Reference in New Issue
Block a user