From: Arlindo da S. <arl...@na...> - 2011-12-29 02:19:23
|
On Thu, Dec 22, 2011 at 3:47 PM, Jennifer Adams <jm...@co...> wrote: > When evaluating the mathematical expression, there's a test to see if the > denominator is close to zero with a precision of e-8. > > if (dequal(*val2,0.0,1e-08)==0) *uval2 = 0; > > This is very problematic and will create numerous problems when dealing with chemical constituents with very low concentrations (ppb). Also, GrADS is not very consistent at the moment with zero tests in other functions ga-> d log(1e-12) Result value = -27.631 ga-> d log(0) Warning from LOG: Data has 1 values <= zero These were set to the undefined value Result value = -9.99e+08 In addition, this "check for zero" really defeats the purpose of IEEE representation of floats/doubles. You want to check whether the mantissa is zero, regardless of exponent. That aside, with the inclusion of the the mask in GrADS 2.0, a much better solution would be to make use of the IEEE float point exception handling feature available with modern compilers (autoconf can check for that). See the attached code snippet for sample usage of the isnan(), isinf(), isnormal() functions. For example, nowadays 1.0/0.0 evaluates to Inf sqrt(-1.) evaluates to NaN exp(VERY_LARGE_NUMBER) evaluates to Inf A faster and more robust approach would be to eliminate these zero tests from the code and examine the validity of the result with built in functions isnan() and isinf(), setting the "mask" when such an IEEE exception is returned. Right now GrADS does not handle overflows, try this: ga-> d exp(1.e249) Result value = inf I believe that you would want to return UNDEFs in this case as well. BTW, the isnormal() built in function can be used to check for zeros, see attached. Arlindo |