[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: float problem



>Date: Tue, 26 Apr 94 17:09:38 GMT
>From: address@hidden (Jean-Francois Foccroulle)
>To: address@hidden
>Subject: float problem

In the above message you wrote:

>We use netCDF and sometimes create and read netCDF files with different
>computers.
>
>Unfortunately I have found a problem when reading a (very) small float from
>a netCDF file on a DEC ALPHA (OSF/1).  I can read this float on a convex and
>on a DECstation 5000/125 (ultrix). The value is approximatively 0.
>
>When I use ncdump
>   -on a convex
>       netcdf wkxy3 {
>          dimensions:
>               lon = 1 ;
>          variables:
>               float wkxy3(lon) ;
>          data:
>          wkxy3 = 0  ;
>       }
>   -on a DECstation 5000
>       netcdf wkxy3 {
>          dimensions:
>               lon = 1 ;
>          variables:
>               float wkxy3(lon) ;
>          data:
>          wkxy3 = 1.401298e-45  ;
>       }
>   -on a DEC ALPHA,
>       a floating exception occurs and a core dump is created.
>
>I guess the origin of the problem is the value itself (less than FLT_MIN)
>But the DECstation 5000 behaviour is better as well as the Convex ...  Do
>you have any suggestion to read properly small float values on a DEC ALPHA ?
>I give you below the netCDF file, encoded with uuencode.  Thanks for your
>help,

Thank *you* for deepening our understanding of the interactions between
the netCDF package and IEEE arithmetic.

The problem is that, by default, the Alpha OSF/1 C compiler doesn't
support gradual underflow.  The floating-point number in question (0x1)
is a subnormal number and the compiler traps all arithmetic performed
on these values (in particular, converting them to decimal
representations).

The solution is to tell the compiler to permit gradual underflow (i.e.
not to trap subnormal floating-point values).  This is done via the 
flag `-ieee_with_inexact'.  For example:

    cc -c -I../libsrc -I../port -DNDEBUG -O -ieee_with_inexact ncdump.c

Add `-ieee_with_inexact ncdump.c' to the CFLAGS macro in the ncdump
makefile and recompile.  It should then work as you expect.

We might incorporate this flag in the next netCDF release.

--------
Steve Emmerson   <address@hidden>