Summary

test egg's approx-equal? cannot distinguish -1. and 1.

Metadata

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.