[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Floating-point round-off problems.

I have been writing geometric algorithms on this machine and the accuracy is an important issue:
try using double precision,
(- 0.6d1 0.59d1)
0.09999999999999964d0  ;;; Better than the sun !
(float (- 0.6d1 0.59d1)0.0)
or build greater tolerance into comparisons

(defvar 1*epsilon* 00.000001)

(defun 1almost-zero? 0(r &optional ( *epsilon*))
  2"Checks if realnum is almost zero"
0  (declare (values boolean))
  (<= (abs r) ))

(defun 1almost-equal? 0(r1 r2 &optional( *epsilon*))
  2"Checks if two realnums are almost equal"
0  (declare (values boolean))
  (<= (abs(- r1 r2)) ))

(defun 1equal-point? 0(point1 point2 &optional( *epsilon*))            ;;; boolean check using epsilon value
  2"Point equality"
0  (declare (values boolean))
  (loop for c1 in point1
	for c2 in point2
	as same = (almost-equal? c1 c2 )
	until (not same)
	finally (return same)))