From: Mate Toth
Subject: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <499d0f3c-f6d7-46f1-a540-28fe4de4c82d@d61g2000hsa.googlegroups.com>
Hi all!

I get the floating point exceptions:
(+  -2.1424108e38 -2.6809636e38)

I searched the web and after all I found the condition system thing -
but I haven't understand how to set it up in the way to round the
number.

Thanks - Matthew

From: Slobodan Blazeski
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <ca609553-9a19-41e2-ab64-07ed4cb0815d@b36g2000hsa.googlegroups.com>
On Nov 17, 7:51 pm, Mate Toth <·······@gmail.com> wrote:
> Hi all!
>
> I get the floating point exceptions:
> (+  -2.1424108e38 -2.6809636e38)
>
> I searched the web and after all I found the condition system thing -
> but I haven't understand how to set it up in the way to round the
> number.
>
> Thanks - Matthew

Check cl-statistics http://compbio.uchsc.edu/Hunter_lab/Hunter/cl-statistics.lisp
for example, you'll have to use  http://www.lisp.org/HyperSpec/Body/contyp_floati_int-overflow.html
instead  of undeflow but the rest should be the same.

Slobodan
From: Robert Dodier
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <94faa890-685e-4ba0-bd83-80ebb8bf8387@d27g2000prf.googlegroups.com>
Mate Toth wrote:

> I get the floating point exceptions:
> (+  -2.1424108e38 -2.6809636e38)
>
> I searched the web and after all I found the condition system thing -
> but I haven't understand how to set it up in the way to round the
> number.

Aside from from the stuff other people have mentioned,
you can tell SBCL to yield floating point infinity or not-a-number
instead of triggering an error.

(sb-ext::set-floating-point-modes :traps nil)
(+  -2.1424108e38 -2.6809636e38)
 => #.SB-EXT:SINGLE-FLOAT-NEGATIVE-INFINITY

That isn't portable -- some Lisp implementations recognize special
floating point values and some don't.

If an arbitrary-precision floating point arithmetic is useful to you,
you might consider using Maxima's bigfloat implementation.
Maxima is a computer algebra system written in Lisp; you could
use it as a library for your own program.

FWIW

Robert Dodier
From: Mate Toth
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <8a9132c2-a77d-41df-b1d0-b8f8561cfa2b@41g2000hsh.googlegroups.com>
Hi All!

I see I explained a bit different problem.. or absolutely not my
problem lol :) -  sorry for this, I was very tired, I think I even
couldn't read - anyway thanks for the answers, it solved it halfway

So the problem:
I want to examine a different kind of evolution algorythm and I have a
bunch of test functions (De jong - http://citeseer.ist.psu.edu/182432.html)
- and there I have to approximate to 10^-6 precision. I don't know why
but for 10^-3 its working  (~400 iter) but from 10^-4 it goes sg like
to infinity - can't get into that precision.

Than I set the values (coerce 'v 'double-float) and it became
seriously better - can approx to 10^-5 (~700 iter) - but it also can't
approx to 10^-6. So it has became better with bigger floats - what can
I change to get into the 10^-6.

Maybe the functions also matter:

(defmacro multiply-genom (genom m)
  (let ((g (gensym)))
  `(loop for ,g in ,genom
	collect (* ,m ,g))))

(defmacro minus-genom (genom1 genom2)
  `(mapcar #'- ,genom1 ,genom2))

(defmacro plus-genom (genom1 genom2)
  `(mapcar #'+ ,genom1 ,genom2))

(defmacro crossover (genom1 genom2 CR)
  (let ((g1 (gensym))
	(g2 (gensym)))

  `(mapcar (lambda (,g1 ,g2) (if (> (random 1.0) ,CR)
			       ,g1
			       ,g2))
    ,genom1
    ,genom2)))


I tried to play around like this:
(sb-ext::float-precision (float (expt 10 -50)))  ;; - but I even
dont't know what it change and it hasn't got an effect on the
performance.

Thanks - Mat
From: Alex Mizrahi
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <47401d98$0$90267$14726298@news.sunsite.dk>
 MT> So the problem:
 MT> I want to examine a different kind of evolution algorythm and I have a
 MT> bunch of test functions (De jong - 
http://citeseer.ist.psu.edu/182432.html)
 MT> - and there I have to approximate to 10^-6 precision. I don't know why
 MT> but for 10^-3 its working  (~400 iter) but from 10^-4 it goes sg like
 MT> to infinity - can't get into that precision.

what is "sg like to infinity"?

typically what causes problem is addition of many of small numbers, and this 
can be fixed by adding it in special way.
however i don't see such stuff in your code, maybe numbers get just too 
small?

 MT> I tried to play around like this:
 MT> (sb-ext::float-precision (float (expt 10 -50)))  ;; - but I even
 MT> dont't know what it change and it hasn't got an effect on the
 MT> performance.

i don't know about SBCL, but you can control it in CLISP:

(SETF (EXT:LONG-FLOAT-DIGITS) 50)

this applies to long-floats. 
From: Mate Toth
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <9bf1537e-2396-4594-b611-2f047d458892@w34g2000hsg.googlegroups.com>
Many thanks! It solved:

(setf sb-ext::float-digits 50)

iter about ~950

> i don't know about SBCL, but you can control it in CLISP:
> (SETF (EXT:LONG-FLOAT-DIGITS) 50)


> what is "sg like to infinity"?
It never reached the desired accuracy and just looped.

> typically what causes problem is addition of many of small numbers, and this
> can be fixed by adding it in special way.
> however i don't see such stuff in your code, maybe numbers get just too
> small?
>

Yes lots of small numbers.

Thanks - M
From: D Herring
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <vPCdnUHNWPP5o6LanZ2dnUVZ_t2inZ2d@comcast.com>
Mate Toth wrote:
> I get the floating point exceptions:
> (+  -2.1424108e38 -2.6809636e38)
> 
> I searched the web and after all I found the condition system thing -
> but I haven't understand how to set it up in the way to round the
> number.

Something like this?
(defun safe+ (x y)
   (handler-case (+ x y)
     (floating-point-overflow ()
       (+ (coerce x 'double-float)
          y))))

(safe+  -2.1424108e38 -2.6809636e38)
-4.823374431179318d38

Note that this is suboptimal (it wraps each addition in a signal 
handler); for heavy use, the signal handler should probably wrap a 
larger calculation unit.  Also, this technique provides no recourse 
for overflowing double-floats... but that would require a new numeric 
class anyway.

- Daniel
From: Alex Mizrahi
Subject: Re: Floating Point Overflow - SBCL - what to set
Date: 
Message-ID: <473f466c$0$90267$14726298@news.sunsite.dk>
 MT> I get the floating point exceptions:
 MT> (+  -2.1424108e38 -2.6809636e38)

 MT> I searched the web and after all I found the condition system thing -
 MT> but I haven't understand how to set it up in the way to round the
 MT> number.

i think you should have limit somewhere, computer memory is quite finite, 
you know..
if you're just not satisied with single-float limit, you can use 
double-float:

[2]> most-positive-double-float
1.7976931348623157d308

that should be fine for practical purposes. some implementations (CLISP) 
also offer:

[3]> most-positive-long-float
8.8080652584198167656L646456992

that's ~10^646456992, i don't think it's practical to have numbers larger 
than that :)

if implementation you're using doesn't have anything larger than 
double-float (10^308), it might be possible to use bignums somehow, but i'm 
afraid it's impractical -- better pick some other implementation if you need 
that large numbers.