Subject: [clisp-list] floating point question

From: Nathan Froyd <[email-masked]>
Date: Mon, 4 Dec 2000 21:43:21 -0500

I'm trying to write a lisp function to do my homework for me (aren't we
all?).  It's reprinted below (along with support):

(setf *warn-on-floating-point-contagion* nil)

(defvar *tolerance* 0.000000001)

(defun close-enough-p (x actual)
  (> *tolerance* (abs (- actual x))))

(defun fixed-point (func x)
  (declare (double-float x))
  (let ((iterations 1))
    (flet ((next-x (z)
                   (funcall func z)))
      (labels ((xloop (z)
                      (let ((new-z (next-x z)))
                        (if (close-enough-p (funcall func new-z)
                                            0)
                            (values new-z iterations)
                          (progn
                            (incf iterations)
                            (print (float new-z))
                            (xloop new-z))))))
        (xloop x)))))

Perhaps my style is bad.  Anyway, the problem I have is that CLISP only
seems to want to do 7 decimal place precision; I would like something
more like 12 or so.  Is there any way to tell CLISP that I would like
things done with something other than SHORT-FLOAT (which is what I
assume it's using)?  This is on Linux x86.

Thanks!
-- 
</nathan>  [email-masked]  |  http://www.rose-hulman.edu/~froydnj/

Yes, God had a deadline.  So He wrote it all in Lisp.

---

From: Bruno Haible <[email-masked]>
Date: Tue, 5 Dec 2000 15:57:51 +0100 (CET)

Nathan Froyd writes:
> Anyway, the problem I have is that CLISP only
> more like 12 or so.

7 decimal places, that's the precision of SINGLE-FLOAT. 16 decimal
places, is DOUBLE-FLOAT, and for more (unlimited), you have LONG-FLOAT.

> Is there any way to tell CLISP that I would like things done with
> something other than SHORT-FLOAT (which is what I assume it's using)?

SHORT-FLOAT is even shorter: 5 decimal places.

All you need to do is to give the initial values in double-float, like
2.718d0, or set *read-default-float-format* to DOUBLE-FLOAT.

Bruno

---

From: Sam Steingold <[email-masked]>
Date: 05 Dec 2000 10:33:50 -0500

> * In message <[email-masked]>
> * On the subject of "[clisp-list] floating point question"
> * Sent on Mon, 4 Dec 2000 21:43:21 -0500
> * Honorable Nathan Froyd <[email-masked]> writes:
>

this is a grave mistake.
floating point contagion should be avoided so this warning should be on!

> (defvar *tolerance* 0.000000001)

this is a single float.
please read the CLISP impnotes 12.1.4.4 (and the same section in CLHS -
the impnotes is an annotation to CLHS!).
CLHS 2.3.2.2 would also be _very_ useful.

>     (flet ((next-x (z) (funcall func z)))
you don't need this `flet', IMO.

>                         (if (close-enough-p (funcall func new-z)

if you have the `flet', why not use it here too?!

> Perhaps my style is bad.

it's a little but schemish.  An ANSI CL is not required to eliminate
tail-recursion, so an explicit iteration would be better, especially
since it is not much harder to write.
(I have something similar in CLLIB/math.lisp).

> Anyway, the problem I have is that CLISP only seems to want to do 7
> decimal place precision; I would like something more like 12 or so.
> This is on Linux x86.

you should look at *READ-DEFAULT-FLOAT-FORMAT*.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Cannot handle the fatal error due to a fatal error in the fatal error handler.

---

From: Paolo Amoroso <[email-masked]>
Date: Wed, 06 Dec 2000 21:12:49 +0100

> floating point contagion should be avoided so this warning should be on!

If you don't set *WARN-ON-FLOATING-POINT-CONTAGION* to NIL with Garnet,
your console gets floooded with warnings :) Is it safe to assume that such
warnings are mostly harmless for systems such as Garnet, which are not
number crunching applications?

Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/

---

From: Bruno Haible <[email-masked]>
Date: Wed, 6 Dec 2000 22:38:16 +0100 (CET)

> number crunching applications?

Yes. Although Garnet does some kinds of number crunching when
computing the optimal size of widgets through constraints.

Bruno