iscanonical.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Define iscanonical macro. ldbl-96 version.
  2. Copyright (C) 2016-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. #ifndef _MATH_H
  16. # error "Never use <bits/iscanonical.h> directly; include <math.h> instead."
  17. #endif
  18. extern int __iscanonicall (long double __x)
  19. __THROW __attribute__ ((__const__));
  20. #define __iscanonicalf(x) ((void) (__typeof (x)) (x), 1)
  21. #define __iscanonical(x) ((void) (__typeof (x)) (x), 1)
  22. #if __HAVE_DISTINCT_FLOAT128
  23. # define __iscanonicalf128(x) ((void) (__typeof (x)) (x), 1)
  24. #endif
  25. /* Return nonzero value if X is canonical. In IEEE interchange binary
  26. formats, all values are canonical, but the argument must still be
  27. converted to its semantic type for any exceptions arising from the
  28. conversion, before being discarded; in extended precision, there
  29. are encodings that are not consistently handled as corresponding to
  30. any particular value of the type, and we return 0 for those. */
  31. #ifndef __cplusplus
  32. # define iscanonical(x) __MATH_TG ((x), __iscanonical, (x))
  33. #else
  34. /* In C++ mode, __MATH_TG cannot be used, because it relies on
  35. __builtin_types_compatible_p, which is a C-only builtin. On the
  36. other hand, overloading provides the means to distinguish between
  37. the floating-point types. The overloading resolution will match
  38. the correct parameter (regardless of type qualifiers (i.e.: const
  39. and volatile)). */
  40. extern "C++" {
  41. inline int iscanonical (float __val) { return __iscanonicalf (__val); }
  42. inline int iscanonical (double __val) { return __iscanonical (__val); }
  43. inline int iscanonical (long double __val) { return __iscanonicall (__val); }
  44. # if __HAVE_DISTINCT_FLOAT128
  45. inline int iscanonical (_Float128 __val) { return __iscanonicalf128 (__val); }
  46. # endif
  47. }
  48. #endif /* __cplusplus */