17[[nodiscard]]
constexpr T
abs(T
t)
19 return (
t >= 0) ?
t : -
t;
24#if (defined(__GNUC__) && !defined(__clang__))
28template<
int> [[nodiscard]]
constexpr double sin (
double x) {
return std::sin (x); }
29template<
int> [[nodiscard]]
constexpr double cos (
double x) {
return std::cos (x); }
30template<
int,
int> [[nodiscard]]
constexpr double log (
double x) {
return std::log (x); }
31template<
int,
int> [[nodiscard]]
constexpr double log2 (
double x) { return ::log (x) /
::log(2); }
32template<
int,
int> [[nodiscard]]
constexpr double log10(
double x) {
return std::log10(x); }
33template<
int> [[nodiscard]]
constexpr double exp (
double x) {
return std::exp (x); }
34template<
int> [[nodiscard]]
constexpr double exp2 (
double x) { return ::exp2 (x); }
35template<
int,
int> [[nodiscard]]
constexpr double pow(
double x,
double y) {
return std::pow(x, y); }
36[[nodiscard]]
constexpr double round(
double x) { return ::round(x); }
37[[nodiscard]]
constexpr float round(
float x) { return ::roundf(x); }
38[[nodiscard]]
constexpr double sqrt (
double x) { return ::sqrt (x); }
42[[nodiscard]]
constexpr double upow(
double x,
unsigned u)
53[[nodiscard]]
constexpr double ipow(
double x,
int i)
55 return (i >= 0) ?
upow(x, i) :
upow(x, -i);
58template<
int ITERATIONS>
59[[nodiscard]]
constexpr double exp(
double x)
72 for (
auto k :
xrange(ITERATIONS)) {
79 int p = (i >= 0) ? i : -i;
93 return x - int(x / y) * y;
96template<
int ITERATIONS>
97[[nodiscard]]
constexpr double sin_iter(
double x)
103 for (
int k = 1; k < (1 + 4 * ITERATIONS); ) {
117template<
int ITERATIONS>
124 for (
int k = 2; k < (2 + 4 * ITERATIONS); ) {
138template<
int ITERATIONS>
139[[nodiscard]]
constexpr double sin(
double x)
166 return sign * cos_iter<ITERATIONS>(x);
168 return sign * sin_iter<ITERATIONS>(x);
172template<
int ITERATIONS>
173[[nodiscard]]
constexpr double cos(
double x)
199 return sign * sin_iter<ITERATIONS>(x);
201 return sign * cos_iter<ITERATIONS>(x);
207template<
int E_ITERATIONS,
int L_ITERATIONS>
208[[nodiscard]]
constexpr double log(
double x)
216 repeat(L_ITERATIONS, [&] {
217 auto ey = cstd::exp<E_ITERATIONS>(y);
218 y = y + 2.0 * (x - ey) / (x + ey);
223template<
int E_ITERATIONS,
int L_ITERATIONS>
224[[nodiscard]]
constexpr double log2(
double x)
226 return cstd::log<E_ITERATIONS, L_ITERATIONS>(x) /
Math::ln2;
229template<
int E_ITERATIONS,
int L_ITERATIONS>
230[[nodiscard]]
constexpr double log10(
double x)
232 return cstd::log<E_ITERATIONS, L_ITERATIONS>(x) /
Math::ln10;
235template<
int E_ITERATIONS,
int L_ITERATIONS>
236[[nodiscard]]
constexpr double pow(
double x,
double y)
238 return cstd::exp<E_ITERATIONS>(cstd::log<E_ITERATIONS, L_ITERATIONS>(x) * y);
241template<
int ITERATIONS>
242[[nodiscard]]
constexpr double exp2(
double x)
244 return cstd::exp<ITERATIONS>(
Math::ln2 * x);
247[[nodiscard]]
constexpr double round(
double x)
249 return narrow_cast<double>(
250 (x >= 0) ? narrow_cast<int>( x + 0.5)
251 : -narrow_cast<int>(-x + 0.5));
254[[nodiscard]]
constexpr float round(
float x)
256 return narrow_cast<float>(
257 (x >= 0) ? narrow_cast<int>( x + 0.5f)
258 : -narrow_cast<int>(-x + 0.5f));
261[[nodiscard]]
constexpr double sqrt(
double x)
266 while (curr != prev) {
268 curr = 0.5 * (curr + x / curr);
constexpr double pow(double x, double y)
constexpr double log(double x)
constexpr double sin_iter(double x)
constexpr double simple_fmod(double x, double y)
constexpr double exp2(double x)
constexpr double sqrt(double x)
constexpr double round(double x)
constexpr double exp(double x)
constexpr double cos_iter(double x)
constexpr double ipow(double x, int i)
constexpr double log10(double x)
constexpr double sin(double x)
constexpr double cos(double x)
constexpr double log2(double x)
constexpr double upow(double x, unsigned u)
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.
constexpr auto xrange(T e)