Skip to content

Commit 3969449

Browse files
committed
[libc++] Move std::abs into __math/abs.h
1 parent 9e44f0d commit 3969449

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

libcxx/include/__math/abs.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
3939
return __builtin_fabs((double)__x);
4040
}
4141

42+
// abs
43+
44+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline float abs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
45+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline double abs(double __x) _NOEXCEPT { return __builtin_fabs(__x); }
46+
47+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long double abs(long double __x) _NOEXCEPT {
48+
return __builtin_fabsl(__x);
49+
}
50+
51+
template <class = int>
52+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long abs(int __x) _NOEXCEPT {
53+
return __builtin_abs(__x);
54+
}
55+
56+
template <class = int>
57+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long abs(long __x) _NOEXCEPT {
58+
return __builtin_labs(__x);
59+
}
60+
61+
template <class = int>
62+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long long abs(long long __x) _NOEXCEPT {
63+
return __builtin_llabs(__x);
64+
}
65+
4266
} // namespace __math
4367

4468
_LIBCPP_END_NAMESPACE_STD

libcxx/include/math.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ extern "C++" {
378378
# include <__math/traits.h>
379379
# include <__math/trigonometric_functions.h>
380380
# include <__type_traits/enable_if.h>
381-
# include <__type_traits/is_floating_point.h>
382381
# include <__type_traits/is_integral.h>
383-
# include <stdlib.h>
384382

385383
// fpclassify relies on implementation-defined constants, so we can't move it to a detail header
386384
_LIBCPP_BEGIN_NAMESPACE_STD

libcxx/include/stdlib.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,7 @@ extern "C++" {
106106
# undef llabs
107107
# endif
108108

109-
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
110-
# if !defined(_LIBCPP_MSVCRT)
111-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); }
112-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); }
113-
# endif // !defined(_LIBCPP_MSVCRT)
114-
115-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT {
116-
return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
117-
}
118-
119-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT {
120-
return __builtin_fabs(__lcpp_x);
121-
}
122-
123-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT {
124-
return __builtin_fabsl(__lcpp_x);
125-
}
109+
# include <__math/abs.h>
126110

127111
// div
128112

0 commit comments

Comments
 (0)