25#ifndef __MATH_TOOLS_HPP__
26#define __MATH_TOOLS_HPP__
30inline auto confined_polynomial(
double r,
double R,
int p1,
int p2,
int dm)
32 double t = 1.0 - std::pow(r / R, 2);
35 return (std::pow(r, p1) * std::pow(t, p2));
38 return (-4 * p1 * p2 * std::pow(r, p1) * std::pow(t, p2 - 1) / std::pow(R, 2) +
39 p1 * (p1 - 1) * std::pow(r, p1 - 2) * std::pow(t, p2) +
40 std::pow(r, p1) * (4 * (p2 - 1) * p2 * std::pow(r, 2) * std::pow(t, p2 - 2) / std::pow(R, 4) -
41 2 * p2 * std::pow(t, p2 - 1) / std::pow(R, 2)));
44 RTE_THROW(
"wrong derivative order");
54 return (T(0) < val) - (val < T(0));
61 if (std::abs(std::round(val__) - val__) > eps__) {
75 for (
int i = 1; i <= n; i++) {
81inline auto round(
double a__,
int n__)
83 double a0 = std::floor(a__);
84 double b = std::round((a__ - a0) * std::pow(10, n__)) / std::pow(10, n__);
88inline auto round(std::complex<double> a__,
int n__)
90 return std::complex<double>(round(a__.real(), n__), round(a__.imag(), n__));
95inline auto hash(
void const* buff,
size_t size, uint64_t h = 5381)
97 unsigned char const* p =
static_cast<unsigned char const*
>(buff);
98 for (
size_t i = 0; i < size; i++) {
99 h = ((h << 5) + h) + p[i];
107 static uint32_t a = 123456;
111 a = (a ^ 61) ^ (a >> 16);
123inline int random<int>()
129inline double random<double>()
131 return static_cast<double>(
random_uint32()) / std::numeric_limits<uint32_t>::max();
135inline std::complex<double> random<std::complex<double>>()
137 return std::complex<double>(random<double>(), random<double>());
141inline float random<float>()
143 return static_cast<float>(random<double>());
147inline std::complex<float> random<std::complex<float>>()
149 return std::complex<float>(random<float>(), random<float>());
153auto abs_diff(T a, T b)
155 return std::abs(a - b);
159auto rel_diff(T a, T b)
161 return std::abs(a - b) / (std::abs(a) + std::abs(b) + 1e-13);
172inline auto conj(std::complex<double> x__)
178inline T zero_if_not_complex(T x__)
184inline T zero_if_not_complex(std::complex<T> x__)
void reset()
Reset device.
Namespace of the SIRIUS library.
bool is_int(T val__, T eps__)
Checks if number is integer with a given tolerance.
T factorial(int n)
Compute a factorial.
auto hash(void const *buff, size_t size, uint64_t h=5381)
Simple hash function.
uint32_t random_uint32(bool reset=false)
Simple random number generator.
auto conj(std::complex< double > x__)
Return complex conjugate of a number.
int sign(T val)
Sign of the variable.
auto conj(double x__)
Return complex conjugate of a number. For a real value this is the number itself.