From ac9e1cece23ca57ea61cd88c341dd2b282a91908 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 4 Feb 2004 05:01:32 +0000 Subject: [PATCH] Fix CLOSE-ENOUGH?. --- v7/src/ssp/xdoc.scm | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/v7/src/ssp/xdoc.scm b/v7/src/ssp/xdoc.scm index 98c352168..3894e2037 100644 --- a/v7/src/ssp/xdoc.scm +++ b/v7/src/ssp/xdoc.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: xdoc.scm,v 1.2 2003/12/29 07:31:19 uid67408 Exp $ +$Id: xdoc.scm,v 1.3 2004/02/04 05:01:32 cph Exp $ -Copyright 2003 Massachusetts Institute of Technology +Copyright 2003,2004 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. @@ -880,21 +880,15 @@ USA. "incorrect") "malformed")))) -(define close-enough? - (let ((machine-epsilon - (let loop ((e 1.)) - (if (> (+ e 1) 1) - (loop (/ e 2)) - (* 2 e))))) - (lambda (z expected tolerance) - (if (= tolerance 0) - (= z expected) - (<= (magnitude (- z expected)) - (/ (* (max tolerance machine-epsilon) - (+ (magnitude z) - (magnitude tolerance) - 2)) - 2)))))) +(define (close-enough? z expected tolerance) + (cond ((= tolerance 0) + (= z expected)) + ((= expected 0) + (<= (magnitude (- z expected)) + (magnitude tolerance))) + (else + (<= (magnitude (- z expected)) + (magnitude (* tolerance expected)))))) (define-unary-xdoc-output 'boolean #f (lambda (elt) -- 2.25.1