From: Paul McNamee
Subject: Portable way to prevent underflow errors
Date: 
Message-ID: <1114@aplcomm.JHUAPL.EDU>
I'm looking for a way to prevent errors caused by exponentiation where I'm
raising a number between [0-1] to an integer [0-infinity) power.  This
would be simple if my underflow were due to division by zero but with
exponentiation
	(expt .9 500) ==> 1.32 e-23    but
	(expt .1 500) ==> Error.       and
Thus it seems hard to predict and prevent the later case (by not calling it).
In my case the obvious solution of returning zero is quite acceptable.
Symbolics supports this with a without-floating-underflow-traps macro.
Does Lucid provide a utility for this?  

Perhaps there is a mathematical way to do this using long-float-epsilon and
least-positive-double-float, but my horribly deficient mathematical mind
hasn't thought up one.

Thanks for any assistance,

  Paul McNamee
  ·······@stdb.jhuapl.edu

From: Barry Margolin
Subject: Re: Portable way to prevent underflow errors
Date: 
Message-ID: <14hsraINNihn@early-bird.think.com>
In article <····@aplcomm.JHUAPL.EDU> @·························@stdb.jhuapl.edu (Paul McNamee) writes:
>Thus it seems hard to predict and prevent the later case (by not calling it).
>In my case the obvious solution of returning zero is quite acceptable.
>Symbolics supports this with a without-floating-underflow-traps macro.
>Does Lucid provide a utility for this?  

Lucid has WITH-FLOATING-POINT-TRAPS:

> (with-floating-point-traps ('() '(floating-point-underflow))
    (expt .1 500))
0.0

You can also set up a handler for the FLOATING-POINT-UNDERFLOW condition.

>Perhaps there is a mathematical way to do this using long-float-epsilon and
>least-positive-double-float, but my horribly deficient mathematical mind
>hasn't thought up one.

I don't think so.  You can generally determine whether the result will be
too small, but that won't help if the underflow occurs in an intermediate
computation.

-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: Thomas A. Russ
Subject: Re: Portable way to prevent underflow errors
Date: 
Message-ID: <21986@venera.isi.edu>
You should take a look at the condition handling section in the 2nd
edition of the CommonLisp reference.

A simple solution to the immediate problem at hand (which I just tried
under lucid 4.??) Transform

	(expt .9 500) ==> 1.32 e-23    but
	(expt .1 500) ==> Error.       and

into:

(handler-case (expt .9 500)
   (floating-point-underflow nil 0))   ==> 1.32...e-23


(handler-case (expt .1 500)
   (floating-point-underflow nil 0))   ==> 0

--

Thomas A. Russ                                             ···@isi.edu    
USC/ISI, 4676 Admiralty Way, Marina del Rey, CA 90292      (310) 822-1511