[Top][All Lists]

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

RE: NaN and Inf in files

From: John W. Eaton
Subject: RE: NaN and Inf in files
Date: Mon, 6 Apr 1998 11:50:04 -0500 (CDT)

On  6-Apr-1998, (Ted Harding) <address@hidden> wrote:

| On 06-Apr-98 Mario Storti wrote:
| > 
| > It seems that Octave refuses to read NaN and Inf's in files.
| It would be very useful to have this facility. For instance I use "NaN" for
| missing data values.
| This hasn't usually mattered to me because I habitually create
| m-files for reading in data, and m-files with NaNs work OK. It is no
| big deal either to get octave to write m-files for saving computed
| data in, but using "save" would be easier!

OK, I should have said that there is no easy way to fix this in the
Octave sources.  But there is a relatively easy way to fix it, at
least for someone familiar with the code in floatconv.c in the libio
code distributed with the GNU libc and libstdc++.  Just make that code
understand how to read the same special tokens that are produced when
writing Inf and NaN values.  For example, on some other systems, when
doing "e", "f", or "g" conversions, the floating point conversion code
understands "Inf" or "Infinity" or "NaN" or "NaNQ" etc.

So I think the bug is really in libio and should be fixed there.
Can someone who wants this feature to work in Octave please report the
problem to the libc/libstdc++ maintainers?  Here is a simple example
(make this work in libio and I think the problem will be solved):

  #include <stdio.h>

  main (void)
    char buf[100];
    double inf = 1.0 / 0.0;
    double nan = 0.0 / 0.0;
    sprintf (buf, "%f %f", inf, nan);
    printf ("%s\n", buf);
    inf = nan = 0.0;
    sscanf (buf, "%lf %lf", &inf, &nan);
    printf ("%f %f\n", inf, nan);
    return 0;

BTW, I tried fixing this once, but got lost in the floatconv code.
Good luck!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]