iscanonical.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Define iscanonical macro. ldbl-96 version.
  17. Copyright (C) 2016-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #ifndef _MATH_H
  31. # error "Never use <bits/iscanonical.h> directly; include <math.h> instead."
  32. #endif
  33. extern int __iscanonicall (long double __x)
  34. __THROW __attribute__ ((__const__));
  35. #define __iscanonicalf(x) ((void) (__typeof (x)) (x), 1)
  36. #define __iscanonical(x) ((void) (__typeof (x)) (x), 1)
  37. #if __HAVE_DISTINCT_FLOAT128
  38. # define __iscanonicalf128(x) ((void) (__typeof (x)) (x), 1)
  39. #endif
  40. /* Return nonzero value if X is canonical. In IEEE interchange binary
  41. formats, all values are canonical, but the argument must still be
  42. converted to its semantic type for any exceptions arising from the
  43. conversion, before being discarded; in extended precision, there
  44. are encodings that are not consistently handled as corresponding to
  45. any particular value of the type, and we return 0 for those. */
  46. #ifndef __cplusplus
  47. # define iscanonical(x) __MATH_TG ((x), __iscanonical, (x))
  48. #else
  49. /* In C++ mode, __MATH_TG cannot be used, because it relies on
  50. __builtin_types_compatible_p, which is a C-only builtin. On the
  51. other hand, overloading provides the means to distinguish between
  52. the floating-point types. The overloading resolution will match
  53. the correct parameter (regardless of type qualifiers (i.e.: const
  54. and volatile)). */
  55. extern "C++" {
  56. inline int iscanonical (float __val) { return __iscanonicalf (__val); }
  57. inline int iscanonical (double __val) { return __iscanonical (__val); }
  58. inline int iscanonical (long double __val) { return __iscanonicall (__val); }
  59. # if __HAVE_DISTINCT_FLOAT128
  60. inline int iscanonical (_Float128 __val) { return __iscanonicalf128 (__val); }
  61. # endif
  62. }
  63. #endif /* __cplusplus */