Re: Floating Underflow/Overflow [message #27319 is a reply to message #27229] |
Tue, 16 October 2001 12:18   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"George N. White III" <WhiteG@dfo-mpo.gc.ca> writes:
> On Mon, 15 Oct 2001, Paul van Delst wrote:
>
>> Kay wrote:
>>> i get Floating Overflow/Underflow error messages during my
>>> calculations, but the result seems to be correct, can these warnings
>>> be ignored then?
>>> [...]
>
> "Seems to be correct" only offers some hope that when you understand
> the reason for underflow you will realize that it doesn't affect
> your results. Even then, you may want to alter the program to
> avoid underflow:
>
> 1. underflow is often an expensive way to set a variable to zero -- when
> the source of underflow is understood it may become obvious that a
> significant chunk of calculation isn't needed and shouldn't be used (e.g.,
> by adding a range test to omit the section where underlow occurs when the
> inputs are "out of bounds").
>
> 2. modern hardware with branch prediction and combined f.p. ops
> is generally tuned for peak performance in typical cases, and can
> fall down very badly when handling exceptions. Even if your current
> program performs adequately, once you have analyzed the underflow
> you may want to document it in case you encounter performance problems
> in the future.
On the other hand, the performance of IDL falls down rather badly when
dealing with conditional tests on large arrays, especially when FOR
loops cannot be avoided. Even using WHERE() usually makes a pretty
large performance hit.
One little trick for avoiding underflows in exponentials might go like
this. If you wish to compute Y = EXP(-X), for large X, then you can
usually use a "mask" variable to avoid the underflow.
MASK = (X LT UPPER_LIMIT)
Y = MASK * EXP(-X*MASK)
Note that this doesn't catch overflows which will be more disastrous.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|