nan.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /***********************************************************************
  2. nan, nanf, nanl - return quiet NaN
  3. These functions shall return a quiet NaN, if available, with content
  4. indicated through tagp.
  5. If the implementation does not support quiet NaNs, these functions
  6. shall return zero.
  7. Calls: strlen(), sprintf(), strtod()
  8. ***********************************************************************/
  9. #include <math.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. double nan (const char *tagp)
  14. {
  15. if (tagp[0] != '\0') {
  16. char buf[6 + strlen (tagp)];
  17. sprintf (buf, "NAN(%s)", tagp);
  18. return strtod (buf, NULL);
  19. }
  20. return NAN;
  21. }
  22. float nanf (const char *tagp)
  23. {
  24. if (tagp[0] != '\0') {
  25. char buf[6 + strlen (tagp)];
  26. sprintf (buf, "NAN(%s)", tagp);
  27. return strtof (buf, NULL);
  28. }
  29. return NAN;
  30. }
  31. #if 0
  32. long double nanl (const char *tagp)
  33. {
  34. if (tagp[0] != '\0') {
  35. char buf[6 + strlen (tagp)];
  36. sprintf (buf, "NAN(%s)", tagp);
  37. return strtold (buf, NULL);
  38. }
  39. return NAN;
  40. }
  41. #endif