home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!warwick!uknet!mcsun!sun4nl!and!jos
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: How is NaN recognized?
- Message-ID: <3421@dozo.and.nl>
- Date: 13 Sep 92 13:54:28 GMT
- References: <3358@dozo.and.nl> <7a0757eb@p3.f6.n249.z2.fidonet.org> <1992Sep8.231535.4925@ecl.psu.edu>
- Organization: AND Software BV Rotterdam
- Lines: 32
-
- In article <1992Sep8.231535.4925@ecl.psu.edu> y2t@ecl.psu.edu writes:
- |A while ago, Gilles_Kohl@spam.fido.de (Gilles Kohl) writes:
- |>
- |>another alternative (beside your suggested use of a finite automaton)
- |>might be the strtod function from the ANSI standard lib:
- |>
- |>double strtod(const char *s, char **enpd)
- |>
- |>strtod returns HUGE_VAL in case of overflow, 0 in case of underflow - in both
- |>cases the standard requires errno to be set to ERANGE. What's really nice about
- |>strtod is that it sets the char * pointed to by enpd to where it stopped
- |>converting - makes error detection easier.
-
- | What about reading floating point values from a binary file?
- |Look at the following codes:
- |
- | int fp;
- | float x;
- | fp = open(filename, O_RONLY);
- | read(fp, &x, sizeof(float));
- |
- | Is there a way to detect if x is a NaN?
-
- I must confess that I'm not a `floating point guru', but I thought that
- IEEE <some number> stated that a NaN doesn't compare equal to any number,
- including a NaN itself. So `if (x != x) printf("A NaN\n");' could do
- the job for you. But I'm not sure what most implementations use when
- floating point numbers are concerned ... I stick with the simple bits ;-)
-
- kind regards,
-
- Jos aka jos@and.nl
-