Skip to content

Commit 28ba4cd

Browse files
committed
[libc++] Granularize more <cmath> includes
1 parent 42da815 commit 28ba4cd

14 files changed

+57
-45
lines changed

libcxx/include/__chrono/formatter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
# include <__format/write_escaped.h>
5050
# include <__memory/addressof.h>
5151
# include <__type_traits/is_specialization.h>
52-
# include <cmath>
5352
# include <ctime>
5453
# include <limits>
5554
# include <locale>

libcxx/include/__format/formatter_floating_point.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
#include <__format/formatter_output.h>
3232
#include <__format/parser_std_format_spec.h>
3333
#include <__iterator/concepts.h>
34+
#include <__math/traits.h>
3435
#include <__memory/allocator.h>
3536
#include <__system_error/errc.h>
3637
#include <__type_traits/conditional.h>
3738
#include <__utility/move.h>
3839
#include <__utility/unreachable.h>
39-
#include <cmath>
4040

4141
#if _LIBCPP_HAS_LOCALIZATION
4242
# include <__locale>
@@ -636,10 +636,10 @@ _LIBCPP_HIDE_FROM_ABI auto __write_using_trailing_zeros(
636636
template <floating_point _Tp, class _CharT, class _FormatContext>
637637
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
638638
__format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) {
639-
bool __negative = std::signbit(__value);
639+
bool __negative = __math::signbit(__value);
640640

641-
if (!std::isfinite(__value)) [[unlikely]]
642-
return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, std::isnan(__value));
641+
if (!__math::isfinite(__value)) [[unlikely]]
642+
return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, __math::isnan(__value));
643643

644644
// Depending on the std-format-spec string the sign and the value
645645
// might not be outputted together:

libcxx/include/__random/binomial_distribution.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/exponential_functions.h>
14+
#include <__math/logarithms.h>
1315
#include <__random/is_valid.h>
1416
#include <__random/uniform_real_distribution.h>
15-
#include <cmath>
1617
#include <iosfwd>
1718

1819
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -115,9 +116,9 @@ template <class _IntType>
115116
binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) : __t_(__t), __p_(__p) {
116117
if (0 < __p_ && __p_ < 1) {
117118
__r0_ = static_cast<result_type>((__t_ + 1) * __p_);
118-
__pr_ = std::exp(
119+
__pr_ = __math::exp(
119120
std::__libcpp_lgamma(__t_ + 1.) - std::__libcpp_lgamma(__r0_ + 1.) - std::__libcpp_lgamma(__t_ - __r0_ + 1.) +
120-
__r0_ * std::log(__p_) + (__t_ - __r0_) * std::log(1 - __p_));
121+
__r0_ * __math::log(__p_) + (__t_ - __r0_) * __math::log(1 - __p_));
121122
__odds_ratio_ = __p_ / (1 - __p_);
122123
}
123124
}

libcxx/include/__random/cauchy_distribution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/trigonometric_functions.h>
1314
#include <__random/is_valid.h>
1415
#include <__random/uniform_real_distribution.h>
15-
#include <cmath>
1616
#include <iosfwd>
1717
#include <limits>
1818

@@ -100,7 +100,7 @@ inline _RealType cauchy_distribution<_RealType>::operator()(_URNG& __g, const pa
100100
static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
101101
uniform_real_distribution<result_type> __gen;
102102
// purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite
103-
return __p.a() + __p.b() * std::tan(3.1415926535897932384626433832795 * __gen(__g));
103+
return __p.a() + __p.b() * __math::tan(3.1415926535897932384626433832795 * __gen(__g));
104104
}
105105

106106
template <class _CharT, class _Traits, class _RT>

libcxx/include/__random/clamp_to_integral.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
#define _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H
1111

1212
#include <__config>
13-
#include <cmath>
13+
#include <__math/rounding_functions.h>
14+
#include <__type_traits/is_floating_point.h>
15+
#include <__type_traits/is_integral.h>
16+
#include <__type_traits/is_same.h>
1417
#include <limits>
1518

1619
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -44,7 +47,7 @@ template <class _IntT, class _RealT>
4447
_LIBCPP_HIDE_FROM_ABI _IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
4548
using _Lim = numeric_limits<_IntT>;
4649
const _IntT __max_val = __max_representable_int_for_float<_IntT, _RealT>();
47-
if (__r >= ::nextafter(static_cast<_RealT>(__max_val), INFINITY)) {
50+
if (__r >= __math::nextafter(static_cast<_RealT>(__max_val), numeric_limits<_RealT>::infinity())) {
4851
return _Lim::max();
4952
} else if (__r <= _Lim::lowest()) {
5053
return _Lim::min();

libcxx/include/__random/exponential_distribution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#define _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/logarithms.h>
1314
#include <__random/generate_canonical.h>
1415
#include <__random/is_valid.h>
1516
#include <__random/uniform_real_distribution.h>
16-
#include <cmath>
1717
#include <iosfwd>
1818
#include <limits>
1919

@@ -96,7 +96,7 @@ template <class _RealType>
9696
template <class _URNG>
9797
_RealType exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) {
9898
static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
99-
return -std::log(result_type(1) - std::generate_canonical<result_type, numeric_limits<result_type>::digits>(__g)) /
99+
return -__math::log(result_type(1) - std::generate_canonical<result_type, numeric_limits<result_type>::digits>(__g)) /
100100
__p.lambda();
101101
}
102102

libcxx/include/__random/extreme_value_distribution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/logarithms.h>
1314
#include <__random/is_valid.h>
1415
#include <__random/uniform_real_distribution.h>
15-
#include <cmath>
1616
#include <iosfwd>
1717
#include <limits>
1818

@@ -100,7 +100,7 @@ template <class _RealType>
100100
template <class _URNG>
101101
_RealType extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) {
102102
static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
103-
return __p.a() - __p.b() * std::log(-std::log(1 - uniform_real_distribution<result_type>()(__g)));
103+
return __p.a() - __p.b() * __math::log(-__math::log(1 - uniform_real_distribution<result_type>()(__g)));
104104
}
105105

106106
template <class _CharT, class _Traits, class _RT>

libcxx/include/__random/gamma_distribution.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#define _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/exponential_functions.h>
14+
#include <__math/logarithms.h>
15+
#include <__math/roots.h>
1316
#include <__random/exponential_distribution.h>
1417
#include <__random/is_valid.h>
1518
#include <__random/uniform_real_distribution.h>
16-
#include <cmath>
1719
#include <iosfwd>
1820
#include <limits>
1921

@@ -114,13 +116,13 @@ _RealType gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type
114116
const result_type __v = __gen(__g);
115117
const result_type __w = __u * (1 - __u);
116118
if (__w != 0) {
117-
const result_type __y = std::sqrt(__c / __w) * (__u - result_type(0.5));
119+
const result_type __y = __math::sqrt(__c / __w) * (__u - result_type(0.5));
118120
__x = __b + __y;
119121
if (__x >= 0) {
120122
const result_type __z = 64 * __w * __w * __w * __v * __v;
121123
if (__z <= 1 - 2 * __y * __y / __x)
122124
break;
123-
if (std::log(__z) <= 2 * (__b * std::log(__x / __b) - __y))
125+
if (__math::log(__z) <= 2 * (__b * __math::log(__x / __b) - __y))
124126
break;
125127
}
126128
}
@@ -131,12 +133,12 @@ _RealType gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type
131133
const result_type __u = __gen(__g);
132134
const result_type __es = __egen(__g);
133135
if (__u <= 1 - __a) {
134-
__x = std::pow(__u, 1 / __a);
136+
__x = __math::pow(__u, 1 / __a);
135137
if (__x <= __es)
136138
break;
137139
} else {
138-
const result_type __e = -std::log((1 - __u) / __a);
139-
__x = std::pow(1 - __a + __a * __e, 1 / __a);
140+
const result_type __e = -__math::log((1 - __u) / __a);
141+
__x = __math::pow(1 - __a + __a * __e, 1 / __a);
140142
if (__x <= __e + __es)
141143
break;
142144
}

libcxx/include/__random/lognormal_distribution.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/exponential_functions.h>
1314
#include <__random/is_valid.h>
1415
#include <__random/normal_distribution.h>
15-
#include <cmath>
1616
#include <iosfwd>
1717
#include <limits>
1818

@@ -69,13 +69,13 @@ class _LIBCPP_TEMPLATE_VIS lognormal_distribution {
6969
// generating functions
7070
template <class _URNG>
7171
_LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) {
72-
return std::exp(__nd_(__g));
72+
return __math::exp(__nd_(__g));
7373
}
7474

7575
template <class _URNG>
7676
_LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) {
7777
typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
78-
return std::exp(__nd_(__g, __pn));
78+
return __math::exp(__nd_(__g, __pn));
7979
}
8080

8181
// property functions

libcxx/include/__random/normal_distribution.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H
1111

1212
#include <__config>
13+
#include <__math/logarithms.h>
14+
#include <__math/roots.h>
1315
#include <__random/is_valid.h>
1416
#include <__random/uniform_real_distribution.h>
15-
#include <cmath>
1617
#include <iosfwd>
1718
#include <limits>
1819

@@ -123,7 +124,7 @@ _RealType normal_distribution<_RealType>::operator()(_URNG& __g, const param_typ
123124
__v = __uni(__g);
124125
__s = __u * __u + __v * __v;
125126
} while (__s > 1 || __s == 0);
126-
result_type __fp = std::sqrt(-2 * std::log(__s) / __s);
127+
result_type __fp = __math::sqrt(-2 * __math::log(__s) / __s);
127128
__v_ = __v * __fp;
128129
__v_hot_ = true;
129130
__up = __u * __fp;

0 commit comments

Comments
 (0)