nan.c 1.3 KB

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