Subject: Re: scanf misses NAN and INF (patch to review)
To: Thor Lancelot Simon <>
From: Emmanuel Dreyfus <>
List: tech-userlevel
Date: 04/04/2007 07:56:39
Thor Lancelot Simon <> wrote:

> > What do you mean? The case where the object is not a float? I'm in case
> > CT_FLOAT, so this should be adressed...
> No.  Not all floating-point formats have "not a number" or IEEE-style
> infinities, and we run on at least two machines where there is no
> floating point format that does, plus at least one where one of the
> available floating points doesn't (though we don't support it).

Please give more details, I'm really clueless on this topic.

I try to fix that bug:

#include <stdio.h>
#include <math.h>

        float f,g;
        int hit;
        char s[512];

        f = sqrt(-1);

        printf("f = %f\n", f);
        snprintf(s, sizeof(s), "%f", f);
        printf("s = \"%s\"\n", s);
        hit = sscanf(s, "%f", &g);
        printf("hit = %d\n", hit);
        printf("g = %f\n\n", g);

        return 0;

On -current, this produces:
f = nan
s = "nan"
hit = 0
g = 0.000000

With my patch:
f = nan
s = "nan"
hit = 1
g = nan

Can you give me an example where the patch would not be appropriate?

Emmanuel Dreyfus