Re: Some comments on the ansi test suite

Raymond Toy <[email protected]>
Newsgroups gmane.lisp.clocc.devel
Message-ID <[email protected]>
>>>>> "Peter" == Peter Van Eynde <[email protected]> writes:

    Peter> On Tue, Jul 09, 2002 at 09:38:28AM -0400, Raymond Toy wrote:
    Peter> These are part of the less useful history of ansi-test. It came from an
    Peter> implementation that seems to have had its share of numeric bugs. So
    Peter> there are a lot of simple tests like this. Of course they fall on their
    Peter> face the moment you change fp format... 
    >> 
    >> What do you propose?  Leave them?  Remove them?  Change them to be be
    >> an approximately equal type of test instead of equality?

    Peter> Replace them with a better test would be nice. As most of them are fp
    Peter> problems we should (IMHO) replace them with "zero knowledge" tests or
    Peter> remove them.

Hmm, I seem not to have sent my proposals to this list.  Here they
are:

;; sin(8*pi/2) = sin(4*pi) = 0.  Assume that our pi is a bit off.  Say
;; pi*(1+eps).  Then sin(8*pi*(1+eps)/2) = sin(4*pi + 4*pi*eps) =
;; sin(4*pi*eps) ~= 4*pi*eps.  Test for this, but allow a fudge factor
;; of 2.
(check-for-bug :alltest-legacy-1045
  (let ((y (sin (* 8 (/ pi 2))))
	(fudge 2))
    (< (abs y) (* fudge (* 4 pi long-float-epsilon))))
  t)

;; As in 1045, cos(pi*(1+eps)/2) = cos(pi/2+pi*eps/2) = -sin(pi*eps/2)
;; ~= -pi*eps/2.  Check that we are close enough.
(check-for-bug :alltest-legacy-1061
  (let ((y (cos (/ pi 2)))
	(fudge 2))
    (< (abs y) (* fudge (* pi long-float-epsilon 1/2))))
  t)

;; As in 1045, tan(x) = sin(x)/cos(x).  When x = pi/2+pi*eps/2, sin(x)
;; is essentially 1, but cos(x) is about pi/2*eps.  So tan(x) =
;; 1/cos(x).  So we have 1/tan(x) = cos(x).  But from 1061, we know
;; that cos(x) ~= -pi*eps/2.  So our check is |1/tan(x) - cos(x)| is
;; close enough to zero.
(check-for-bug :alltest-legacy-1073
  (let* ((fudge 2)
	 (val (tan (/ pi 2)))
	 (ref (cos (/ pi 2)))
	 (rel-err (abs (/ (- (/ val) ref) ref))))
    (< rel-err (* fudge long-float-epsilon)))
  t)

Note that Clisp fails test 1073 because, strangely, 1/tan(x) gives
a quite different value from cos(x) here.

Ray


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.