nan.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. libm_hidden_def(nan)
  29. libm_hidden_proto(nanf)
  30. float nanf (const char *tagp)
  31. {
  32. if (tagp[0] != '\0') {
  33. char buf[6 + strlen (tagp)];
  34. sprintf (buf, "NAN(%s)", tagp);
  35. return strtof (buf, NULL);
  36. }
  37. return NAN;
  38. }
  39. libm_hidden_def(nanf)
  40. #if defined __UCLIBC_HAS_LONG_DOUBLE_MATH__
  41. libm_hidden_proto(nanl)
  42. long double nanl (const char *tagp)
  43. {
  44. if (tagp[0] != '\0') {
  45. char buf[6 + strlen (tagp)];
  46. sprintf (buf, "NAN(%s)", tagp);
  47. return strtold (buf, NULL);
  48. }
  49. return NAN;
  50. }
  51. libm_hidden_def(nanl)
  52. #endif