Opened 12 years ago

Closed 10 years ago

#935 closed defect (fixed)

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

Reported by: Alaric Snell-Pym Owned by: foof
Priority: major Milestone: someday
Component: extensions Version: 4.8.x
Keywords: test Cc:
Estimated difficulty:

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))

Change History (1)

comment:1 Changed 10 years ago by Alex Shinn

Resolution: fixed
Status: newclosed

This was fixed ages ago.

Note: See TracTickets for help on using tickets.