nan.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. /***********************************************************************
  8. nan, nanf, nanl - return quiet NaN
  9. These functions shall return a quiet NaN, if available, with content
  10. indicated through tagp.
  11. If the implementation does not support quiet NaNs, these functions
  12. shall return zero.
  13. Calls: strlen(), sprintf(), strtod()
  14. ***********************************************************************/
  15. #include <math.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. double nan (const char *tagp)
  20. {
  21. if (tagp[0] != '\0') {
  22. char buf[6 + strlen (tagp)];
  23. sprintf (buf, "NAN(%s)", tagp);
  24. return strtod (buf, NULL);
  25. }
  26. return NAN;
  27. }
  28. float nanf (const char *tagp)
  29. {
  30. if (tagp[0] != '\0') {
  31. char buf[6 + strlen (tagp)];
  32. sprintf (buf, "NAN(%s)", tagp);
  33. return strtof (buf, NULL);
  34. }
  35. return NAN;
  36. }
  37. #if 0
  38. long double nanl (const char *tagp)
  39. {
  40. if (tagp[0] != '\0') {
  41. char buf[6 + strlen (tagp)];
  42. sprintf (buf, "NAN(%s)", tagp);
  43. return strtold (buf, NULL);
  44. }
  45. return NAN;
  46. }
  47. #endif