[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Floating point coercion problem?
- To: info-macl@cambridge.apple.com
- Subject: Floating point coercion problem?
- From: John M. Canning <jc@cvl.umd.edu>
- Date: Thu, 28 Jun 90 16:59:29 EDT
Thank you for your reponse about the floating point co-processor (my v1.3.2
documentation is packed in a box waiting to be moved to another building).
Here is a floating point problem that could be a problem with the IEEE
floating point representation or MACL's integer to floating point conversion.
Consider the following function which should always return T:
(defun foo (x) (<= (- (+ x (sqrt 2)) x) (sqrt 2)))
But in MACL
(foo 6) => T
(foo 7) => nil
This table summarizes foo's results for some integers:
x foo
-------- -------
0-6 T
7-30 nil
31-126 T
127-2046 nil
2047-4094 T
4095-9999 nil
(I only tested up to 9999).
Furthermore, the error generated by adding and subtracting the same integer
is greater than long-float-epsilon.
(- (- (+ 7 (sqrt 2)) 7) (sqrt 2)) => 6.661338147750939E-16
long-float-epsilon => 1.1107651257114E-16
- John Canning