home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13608 < prev    next >
Encoding:
Internet Message Format  |  1992-09-13  |  1.6 KB

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