You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.3KB

  1. // -*- C++ -*- C library enhancements header.
  2. // Copyright (C) 2016-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/bits/std_abs.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{cmath, cstdlib}
  23. */
  24. #ifndef _GLIBCXX_BITS_STD_ABS_H
  25. #define _GLIBCXX_BITS_STD_ABS_H
  26. #pragma GCC system_header
  27. #include <bits/c++config.h>
  28. #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
  29. #include_next <stdlib.h>
  30. #ifdef __CORRECT_ISO_CPP_MATH_H_PROTO
  31. # include_next <math.h>
  32. #endif
  33. #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
  34. #undef abs
  35. extern "C++"
  36. {
  37. namespace std _GLIBCXX_VISIBILITY(default)
  38. {
  39. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  40. using ::abs;
  41. #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
  42. inline long
  43. abs(long __i) { return __builtin_labs(__i); }
  44. #endif
  45. #ifdef _GLIBCXX_USE_LONG_LONG
  46. inline long long
  47. abs(long long __x) { return __builtin_llabs (__x); }
  48. #endif
  49. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  50. // 2192. Validity and return type of std::abs(0u) is unclear
  51. // 2294. <cstdlib> should declare abs(double)
  52. // 2735. std::abs(short), std::abs(signed char) and others should return int
  53. #ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
  54. inline _GLIBCXX_CONSTEXPR double
  55. abs(double __x)
  56. { return __builtin_fabs(__x); }
  57. inline _GLIBCXX_CONSTEXPR float
  58. abs(float __x)
  59. { return __builtin_fabsf(__x); }
  60. inline _GLIBCXX_CONSTEXPR long double
  61. abs(long double __x)
  62. { return __builtin_fabsl(__x); }
  63. #endif
  64. #if defined(__GLIBCXX_TYPE_INT_N_0)
  65. inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
  66. abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
  67. #endif
  68. #if defined(__GLIBCXX_TYPE_INT_N_1)
  69. inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
  70. abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; }
  71. #endif
  72. #if defined(__GLIBCXX_TYPE_INT_N_2)
  73. inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
  74. abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; }
  75. #endif
  76. #if defined(__GLIBCXX_TYPE_INT_N_3)
  77. inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
  78. abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; }
  79. #endif
  80. #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
  81. inline _GLIBCXX_CONSTEXPR
  82. __float128
  83. abs(__float128 __x)
  84. { return __x < 0 ? -__x : __x; }
  85. #endif
  86. _GLIBCXX_END_NAMESPACE_VERSION
  87. } // namespace
  88. } // extern "C"++"
  89. #endif // _GLIBCXX_BITS_STD_ABS_H