ALFI
Advanced Library for Function Interpolation
|
Functions | |
template<typename Number = DefaultNumber> | |
bool | are_equal (const Number &a, const Number &b, const Number &epsilon=std::numeric_limits< Number >::epsilon()) |
template<typename Number, typename ExponentType> | |
Number | binpow (Number x, ExponentType n) |
Computes the power of a number using binary exponentiation. | |
bool alfi::util::numeric::are_equal | ( | const Number & | a, |
const Number & | b, | ||
const Number & | epsilon = std::numeric_limits<Number>::epsilon() ) |
Number alfi::util::numeric::binpow | ( | Number | x, |
ExponentType | n ) |
Computes the power of a number using binary exponentiation.
Calculates \(x^n\) in \(O(\log{n})\) operations using the binary (exponentiation by squaring) method.
It supports both signed and unsigned exponent types (ExponentType
).
If the exponent is negative, the function computes the reciprocal of the positive exponentiation.
x | the base |
n | the exponent |