clisp-list

 [clisp-list] floating point question From: Nathan Froyd - 2000-12-05 02:45:44 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! -- froydnj@... | http://www.rose-hulman.edu/~froydnj/ Yes, God had a deadline. So He wrote it all in Lisp.
 Re: [clisp-list] floating point question From: Bruno Haible - 2000-12-05 14:58:22 Nathan Froyd writes: > 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. 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
 Re: [clisp-list] floating point question From: Sam Steingold - 2000-12-05 15:35:06 > * In message <20001204214321.F8327@...> > * On the subject of "[clisp-list] floating point question" > * Sent on Mon, 4 Dec 2000 21:43:21 -0500 > * Honorable Nathan Froyd writes: > > (setf *warn-on-floating-point-contagion* nil) 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. > (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))) you don't need this `flet', IMO. > (labels ((xloop (z) > (let ((new-z (next-x z))) > (if (close-enough-p (funcall func new-z) if you have the `flet', why not use it here too?! > 0) > (values new-z iterations) > (progn > (incf iterations) > (print (float new-z)) > (xloop new-z)))))) > (xloop x))))) > > 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. > 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. you should look at *READ-DEFAULT-FLOAT-FORMAT*. -- Sam Steingold (http://www.podval.org/~sds) Support Israel's right to defend herself! ; Cannot handle the fatal error due to a fatal error in the fatal error handler.
 Re: [clisp-list] floating point question From: Paolo Amoroso - 2000-12-06 20:13:24 On 05 Dec 2000 10:33:50 -0500, Sam Steingold wrote: > > * Honorable Nathan Froyd writes: > > > > (setf *warn-on-floating-point-contagion* nil) > > this is a grave mistake. > 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/
 Re: [clisp-list] floating point question From: Bruno Haible - 2000-12-06 21:38:34 Paolo Amoroso writes: > 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? Yes. Although Garnet does some kinds of number crunching when computing the optimal size of widgets through constraints. Bruno