ALFI
Advanced Library for Function Interpolation
Loading...
Searching...
No Matches
alfi::util::numeric Namespace Reference

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.
 

Function Documentation

◆ are_equal()

template<typename Number = DefaultNumber>
bool alfi::util::numeric::are_equal ( const Number & a,
const Number & b,
const Number & epsilon = std::numeric_limits<Number>::epsilon() )

◆ binpow()

template<typename Number, typename ExponentType>
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.

Parameters
xthe base
nthe exponent
Returns
\(x^n\)