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