Skip to content

Commit d2734b2

Browse files
committed
[libc++] Avoid including <cmath> in <compare>
1 parent 589b21f commit d2734b2

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

libcxx/include/__compare/strong_order.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include <__compare/compare_three_way.h>
1414
#include <__compare/ordering.h>
1515
#include <__config>
16+
#include <__math/exponential_functions.h>
17+
#include <__math/traits.h>
1618
#include <__type_traits/conditional.h>
1719
#include <__type_traits/decay.h>
1820
#include <__utility/forward.h>
1921
#include <__utility/priority_tag.h>
20-
#include <cmath>
2122
#include <cstdint>
2223
#include <limits>
2324

@@ -66,27 +67,27 @@ struct __fn {
6667
return strong_ordering::greater;
6768
} else if (__t == __u) {
6869
if constexpr (numeric_limits<_Dp>::radix == 2) {
69-
return std::signbit(__u) <=> std::signbit(__t);
70+
return __math::signbit(__u) <=> __math::signbit(__t);
7071
} else {
7172
// This is bullet 3 of the IEEE754 algorithm, relevant
7273
// only for decimal floating-point;
7374
// see https://stackoverflow.com/questions/69068075/
74-
if (__t == 0 || std::isinf(__t)) {
75-
return std::signbit(__u) <=> std::signbit(__t);
75+
if (__t == 0 || __math::isinf(__t)) {
76+
return __math::signbit(__u) <=> __math::signbit(__t);
7677
} else {
7778
int __texp, __uexp;
78-
(void)std::frexp(__t, &__texp);
79-
(void)std::frexp(__u, &__uexp);
79+
(void)__math::frexp(__t, &__texp);
80+
(void)__math::frexp(__u, &__uexp);
8081
return (__t < 0) ? (__texp <=> __uexp) : (__uexp <=> __texp);
8182
}
8283
}
8384
} else {
8485
// They're unordered, so one of them must be a NAN.
8586
// The order is -QNAN, -SNAN, numbers, +SNAN, +QNAN.
86-
bool __t_is_nan = std::isnan(__t);
87-
bool __u_is_nan = std::isnan(__u);
88-
bool __t_is_negative = std::signbit(__t);
89-
bool __u_is_negative = std::signbit(__u);
87+
bool __t_is_nan = __math::isnan(__t);
88+
bool __u_is_nan = __math::isnan(__u);
89+
bool __t_is_negative = __math::signbit(__t);
90+
bool __u_is_negative = __math::signbit(__u);
9091
using _IntType =
9192
conditional_t< sizeof(__t) == sizeof(int32_t),
9293
int32_t,

libcxx/include/__compare/weak_order.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#include <__compare/ordering.h>
1414
#include <__compare/strong_order.h>
1515
#include <__config>
16+
#include <__math/traits.h>
1617
#include <__type_traits/decay.h>
1718
#include <__utility/forward.h>
1819
#include <__utility/priority_tag.h>
19-
#include <cmath>
2020

2121
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
2222
# pragma GCC system_header
@@ -51,10 +51,10 @@ struct __fn {
5151
return weak_ordering::greater;
5252
} else {
5353
// Otherwise, at least one of them is a NaN.
54-
bool __t_is_nan = std::isnan(__t);
55-
bool __u_is_nan = std::isnan(__u);
56-
bool __t_is_negative = std::signbit(__t);
57-
bool __u_is_negative = std::signbit(__u);
54+
bool __t_is_nan = __math::isnan(__t);
55+
bool __u_is_nan = __math::isnan(__u);
56+
bool __t_is_negative = __math::signbit(__t);
57+
bool __u_is_negative = __math::signbit(__u);
5858
if (__t_is_nan && __u_is_nan) {
5959
return (__u_is_negative <=> __t_is_negative);
6060
} else if (__t_is_nan) {

libcxx/include/compare

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ namespace std {
162162
#endif
163163

164164
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
165+
# include <cmath>
165166
# include <type_traits>
166167
#endif
167168

libcxx/test/libcxx/transitive_includes/cxx23.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ codecvt string
105105
codecvt tuple
106106
codecvt typeinfo
107107
codecvt version
108-
compare cmath
109108
compare cstddef
110109
compare cstdint
111110
compare limits

libcxx/test/libcxx/transitive_includes/cxx26.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ codecvt string
105105
codecvt tuple
106106
codecvt typeinfo
107107
codecvt version
108-
compare cmath
109108
compare cstddef
110109
compare cstdint
111110
compare limits

0 commit comments

Comments
 (0)