s_isnan.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Return 1 if argument is a NaN, else 0.
  2. Copyright (C) 2007-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* Ugly kludge to avoid declarations. */
  16. #define __isnanf not___isnanf
  17. #define isnanf not_isnanf
  18. #define __GI___isnanf not__GI___isnanf
  19. #include <math.h>
  20. #include <math_private.h>
  21. #include <math_ldbl_opt.h>
  22. #undef __isnanf
  23. #undef isnanf
  24. #undef __GI___isnanf
  25. int
  26. __isnan (double x)
  27. {
  28. uint64_t ix;
  29. EXTRACT_WORDS64 (ix, x);
  30. return ix * 2 > 0xffe0000000000000ul;
  31. }
  32. hidden_def (__isnan)
  33. weak_alias (__isnan, isnan)
  34. /* It turns out that the 'double' version will also always work for
  35. single-precision. */
  36. strong_alias (__isnan, __isnanf)
  37. weak_alias (__isnan, isnanf)
  38. /* ??? GCC 4.8 fails to look through chains of aliases with asm names
  39. attached. Work around this for now. */
  40. hidden_ver (__isnan, __isnanf)
  41. #ifdef NO_LONG_DOUBLE
  42. strong_alias (__isnan, __isnanl)
  43. weak_alias (__isnan, isnanl)
  44. #endif
  45. #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
  46. compat_symbol (libc, __isnan, __isnanl, GLIBC_2_0);
  47. compat_symbol (libc, isnan, isnanl, GLIBC_2_0);
  48. #endif