isfinite.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Test for finite value (zero, subnormal, or normal, and not infinite or NaN).
  2. Copyright (C) 2007-2014 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License along
  12. with this program; if not, see <http://www.gnu.org/licenses/>. */
  13. /* Written by Ben Pfaff <blp@gnu.org>, 2007. */
  14. #include <config.h>
  15. #include "isnanf-nolibm.h"
  16. #include "isnand-nolibm.h"
  17. #include "isnanl-nolibm.h"
  18. /* The "cc" compiler on HP-UX 11.11, when optimizing, simplifies the test
  19. x - y == 0.0 to x == y, a simplification which is invalid when x and y
  20. are Infinity. Disable this optimization. */
  21. #if defined __hpux && !defined __GNUC__
  22. static float zerof;
  23. static double zerod;
  24. static long double zerol;
  25. #else
  26. # define zerof 0.f
  27. # define zerod 0.
  28. # define zerol 0.L
  29. #endif
  30. int gl_isfinitef (float x)
  31. {
  32. return !isnanf (x) && x - x == zerof;
  33. }
  34. int gl_isfinited (double x)
  35. {
  36. return !isnand (x) && x - x == zerod;
  37. }
  38. int gl_isfinitel (long double x)
  39. {
  40. return !isnanl (x) && x - x == zerol;
  41. }