Shared implementation of pow() for Affine, Taylor, and TaylorModel.
More...
#include <sigma/detail/numeric.hpp>
#include <stdexcept>
Go to the source code of this file.
|
| namespace | sigma |
| | The primary namespace for the sigma library.
|
|
| template<typename X, typename U, typename MakePoint> |
| X | sigma::detail::pow_impl (const X &a, const U &power, MakePoint &&make_point) |
| | Implements x^y, shared by Affine::pow, Taylor::pow, and TaylorModel::pow.
|
Shared implementation of pow() for Affine, Taylor, and TaylorModel.
◆ pow_impl()
template<typename X, typename U, typename MakePoint>
| X sigma::detail::pow_impl |
( |
const X & | a, |
|
|
const U & | power, |
|
|
MakePoint && | make_point ) |
Implements x^y, shared by Affine::pow, Taylor::pow, and TaylorModel::pow.
All three representations compute a power the same way: compose from log and exp for a strictly one-signed range/bound, fall back to repeated multiplication for a zero-containing range/bound with a positive integer exponent (log(a) and log(-a) both require a strictly one-signed domain, so neither applies there), and throw for everything else that isn't real-valued. Only two things differ between the three call sites: how to build a fresh "point" instance of X at a given value (a plain Affine<T>(v) vs. a Taylor<T>/TaylorModel<T> that also needs to carry the argument's truncation order) – supplied here as make_point rather than hard-coded – and which free log/exp overload applies, which ordinary argument-dependent lookup resolves for whichever X is used.
- Template Parameters
-
| X | The representation type (Affine<T>, Taylor<T>, or TaylorModel<T>). |
| U | The type of the exponent. |
| MakePoint | A callable taking X::value_t and returning an X that represents that single value, with the same truncation order (if any) as a. |
- Parameters
-
| [in] | a | The value whose power is computed. |
| [in] | power | The exponent. Named power rather than the more usual exp so that the unqualified calls to the exponential function exp(...) below – deliberately unqualified, so that argument-dependent lookup finds whichever representation's exp/log overload matches X, rather than the one visible at this template's own definition point, i.e. wherever pow.hpp happens to first get included – aren't shadowed by the parameter. |
| [in] | make_point | A callable that constructs a new X at a given value. |
- Returns
a raised to power.
- Exceptions
-
| std::domain_error | If a contains 0 and power is negative, or if a contains non-positive values (and is not exactly the point 0) and power is not an integer. Strong throw guarantee. |
| std::bad_alloc | If memory allocation fails. Strong throw guarantee. |