[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Locate an underflow
Paul van Delst <paul.vandelst@noaa.gov> writes:
> Hmm. I do see your point, but if I grab someone else's code (not
> just IDL code BTW) the first thing I do is run their supplied test
> case (I hope there is one) with all warning flags on (for IDL,
> !EXCEPT = 2; for Fortran or similar, set the platform specific
> compiler switch to trap under/overflows, divide by zero, etc.).
>
> If, on running said code, I get a crapload of underflow errors, it's
> an indication that that either a) the code hasn't been tested very
> well or b) the programmer didn't really think about the problem
> enough (and I'm guilty of both of these.... most of the time
> actually). If there are (usually harmelss) underflow errors, how do
> I know that there won't be other more serious errors at some point
> for different input?
Yah, but consider the difference between the following bits of code:
1> y = exp(-x^2)
2> u = x^2
2> sz = size(x)
2> isdouble = sz(sz(0)+1) EQ 5
2> mask = u LT alog(machar(double=isdouble).xmax)
2> y = mask*exp(-u*mask)
Both sets of code accomplish the same thing, computing a gaussian
function, except the second one avoids bogus underflow error messages.
Which one do you think I'd rather write? :-) Which one shows the
original mathematical intent more ?
Craig
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------