nan.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. long double nanl (const char *tagp)
  42. {
  43. if (tagp[0] != '\0') {
  44. char buf[6 + strlen (tagp)];
  45. sprintf (buf, "NAN(%s)", tagp);
  46. return strtold (buf, NULL);
  47. }
  48. return NAN;
  49. }
  50. libm_hidden_def(nanl)
  51. #endif