[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-janitors] #1157: test egg 'approx-equal?' bug?
From: |
Chicken Trac |
Subject: |
[Chicken-janitors] #1157: test egg 'approx-equal?' bug? |
Date: |
Fri, 19 Sep 2014 01:46:33 -0000 |
#1157: test egg 'approx-equal?' bug?
---------------------+------------------------------------------------------
Reporter: retroj | Owner:
Type: defect | Status: new
Priority: major | Milestone: someday
Component: unknown | Version: 4.9.x
Keywords: |
---------------------+------------------------------------------------------
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))
--
Ticket URL: <http://bugs.call-cc.org/ticket/1157>
CHICKEN Scheme <http://www.call-with-current-continuation.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.
- [Chicken-janitors] #1157: test egg 'approx-equal?' bug?,
Chicken Trac <=