Summary
test egg's approx-equal? cannot distinguish -1. and 1.
Metadata
- Id: 5d423a126c247a4d3459364df4458582440d0894
- Trac id: 935
- Type: defect
- Reporter: alaric
- Owner: foof
- Cc:
- Status: closed
- Component: extensions
- Estimated difficulty:
- Resolution: fixed
- Priority: major
- Milestone: someday
- Version: 4.8.x
- Changetime: 2014-07-30 14:58:02 UTC
- Created: 2012-10-18 17:23:40 UTC
- Keywords: test
Description
#;1> (define (approx-equal? a b epsilon) > (< (abs (- 1 (abs (if (zero? b) (+ 1 a) (/ a b))))) > epsilon)) #;2> (approx-equal? -1. 1. 1e-05) #t
Looking at the code, the problem is clear: the inner abs destroys the difference between 1. (a and b are near-identical) and -1. (a and b are near-identical apart from differing signs), and should be removed:
(define (approx-equal? a b epsilon)
(< (abs (- 1 (if (zero? b) (+ 1 a) (/ a b))))
epsilon))
Changes and comments
[2014-07-30 14:58:02 UTC] ashinn changed status from new to closed
[2014-07-30 14:58:02 UTC] ashinn set resolution to fixed
[2014-07-30 14:58:02 UTC] ashinn wrote:
This was fixed ages ago.