Opened 10 years ago

Closed 10 years ago

#1157 closed defect (fixed)

test egg 'approx-equal?' bug?

Reported by: John Foerch Owned by: Alex Shinn
Priority: major Milestone: someday
Component: extensions Version: 4.9.x
Keywords: test Cc:
Estimated difficulty:

Description

There may be a bug in 'approx-equal?' in the test egg.

I was puzzled as to why testing against an expected value of 0.0 always
seems to fail, even with a large epsilon (1.0).

(use test)
(test 0.0 1e-18) => [FAIL]

Here is the source code of 'approx-equal?' for reference:

(define (approx-equal? a b epsilon)

(cond

((> (abs a) (abs b))

(approx-equal? b a epsilon))

((zero? b)

(< (abs a) epsilon))

(else

(< (abs (/ (- a b) b)) epsilon))))

I note that the conditional branch (zero? b), which is apparently a
special case for testing against 0, will never be reached unless both a
and b are 0, because if b is 0 the absolute value of any other number is
greater, so the previous condition will catch it and flip a and b.

Should that middle condition instead be the following?

((zero? a)

(< (abs b) epsilon))

Change History (2)

comment:1 Changed 10 years ago by Mario Domenech Goulart

Component: unknownextensions
Keywords: test added
Owner: set to Alex Shinn
Status: newassigned

comment:2 Changed 10 years ago by Alex Shinn

Resolution: fixed
Status: assignedclosed

Thanks! This was a bug and was also present in chibi. Fixed.

Note: See TracTickets for help on using tickets.