Pow

Trait Pow 

Source
pub trait Pow<ExponentType>: Sized {
    type Error: Error;

    // Required methods
    fn try_pow(self, exponent: ExponentType) -> Result<Self, Self::Error>;
    fn pow(self, exponent: ExponentType) -> Self;
}
Expand description

A trait for computing the power of a number (base^exponent).

This trait provides an interface for raising a Self type (the base) to a power specified by ExponentType. It includes both a fallible version (try_pow) that performs validation and an infallible version (pow) that may panic in debug builds if validation fails.

§Type Parameters

  • ExponentType: The type of the exponent. This can be a real number type (like f64 or RealRugStrictFinite<P>) or an integer type (like i32, u32, etc.).

Required Associated Types§

Source

type Error: Error

The error type that can be returned by the try_pow method. This type must implement std::error::Error for proper error handling.

Required Methods§

Source

fn try_pow(self, exponent: ExponentType) -> Result<Self, Self::Error>

Attempts to compute self (the base) raised to the power of exponent.

This method performs validation on the base and exponent according to defined policies (e.g., StrictFinitePolicy). It also checks for domain errors specific to the power operation, such as a negative real base with a non-integer real exponent, or a zero base with a negative exponent. Finally, it validates the computed result.

§Arguments
  • exponent: The exponent to raise self to.
Source

fn pow(self, exponent: ExponentType) -> Self

Computes self (the base) raised to the power of exponent.

This method provides a potentially more performant way to compute the power, especially in release builds, by possibly omitting some checks performed by try_pow.

§Behavior
  • In debug builds, this method typically calls try_pow(exponent).unwrap(), meaning it will panic if try_pow would return an error.
  • In release builds, it may call the underlying power function directly. While input validation might be skipped, output validation (e.g., checking if the result is finite) might still occur implicitly if the underlying power function produces non-finite results (like NaN or Infinity) from finite inputs, which are then caught by policies like StrictFinitePolicy if applied to the output.
§Arguments
  • exponent: The exponent to raise self to.
§Returns

The result of self raised to the power of exponent.

§Panics
  • Panics in debug builds if try_pow would return an error.
  • Behavior regarding panics in release builds depends on the specific implementation and the underlying power function. For example, f64::powf itself does not panic but can return NaN or Infinity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Pow<&f64> for f64

Source§

fn pow(self, exponent: &f64) -> Self

Raises th number self to the power exponent.

Source§

type Error = PowRealBaseRealExponentErrors<f64>

Source§

fn try_pow(self, exponent: &f64) -> Result<Self, Self::Error>

Source§

impl Pow<&f64> for Complex<f64>

Source§

fn pow(self, exponent: &f64) -> Self

Raises th number self to the power exponent.

Source§

type Error = PowComplexBaseRealExponentErrors<Complex<f64>>

Source§

fn try_pow(self, exponent: &f64) -> Result<Self, Self::Error>

Source§

impl Pow<i8> for f64

Source§

fn pow(self, exponent: i8) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, i8>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i8) -> Result<Self, Self::Error>

Source§

impl Pow<i8> for Complex<f64>

Source§

fn pow(self, exponent: i8) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, i8>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i8) -> Result<Self, Self::Error>

Source§

impl Pow<i16> for f64

Source§

fn pow(self, exponent: i16) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, i16>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i16) -> Result<Self, Self::Error>

Source§

impl Pow<i16> for Complex<f64>

Source§

fn pow(self, exponent: i16) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, i16>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i16) -> Result<Self, Self::Error>

Source§

impl Pow<i32> for f64

Source§

fn pow(self, exponent: i32) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, i32>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i32) -> Result<Self, Self::Error>

Source§

impl Pow<i32> for Complex<f64>

Source§

fn pow(self, exponent: i32) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, i32>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i32) -> Result<Self, Self::Error>

Source§

impl Pow<i64> for f64

Source§

fn pow(self, exponent: i64) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, i64>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i64) -> Result<Self, Self::Error>

Source§

impl Pow<i64> for Complex<f64>

Source§

fn pow(self, exponent: i64) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, i64>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i64) -> Result<Self, Self::Error>

Source§

impl Pow<i128> for f64

Source§

fn pow(self, exponent: i128) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, i128>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i128) -> Result<Self, Self::Error>

Source§

impl Pow<i128> for Complex<f64>

Source§

fn pow(self, exponent: i128) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, i128>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: i128) -> Result<Self, Self::Error>

Source§

impl Pow<isize> for f64

Source§

fn pow(self, exponent: isize) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, isize>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: isize) -> Result<Self, Self::Error>

Source§

impl Pow<isize> for Complex<f64>

Source§

fn pow(self, exponent: isize) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, isize>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: isize) -> Result<Self, Self::Error>

Source§

impl Pow<u8> for f64

Source§

fn pow(self, exponent: u8) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, u8>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u8) -> Result<Self, Self::Error>

Source§

impl Pow<u8> for Complex<f64>

Source§

fn pow(self, exponent: u8) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, u8>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u8) -> Result<Self, Self::Error>

Source§

impl Pow<u16> for f64

Source§

fn pow(self, exponent: u16) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, u16>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u16) -> Result<Self, Self::Error>

Source§

impl Pow<u16> for Complex<f64>

Source§

fn pow(self, exponent: u16) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, u16>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u16) -> Result<Self, Self::Error>

Source§

impl Pow<u32> for f64

Source§

fn pow(self, exponent: u32) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, u32>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u32) -> Result<Self, Self::Error>

Source§

impl Pow<u32> for Complex<f64>

Source§

fn pow(self, exponent: u32) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, u32>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u32) -> Result<Self, Self::Error>

Source§

impl Pow<u64> for f64

Source§

fn pow(self, exponent: u64) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, u64>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u64) -> Result<Self, Self::Error>

Source§

impl Pow<u64> for Complex<f64>

Source§

fn pow(self, exponent: u64) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, u64>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u64) -> Result<Self, Self::Error>

Source§

impl Pow<u128> for f64

Source§

fn pow(self, exponent: u128) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, u128>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u128) -> Result<Self, Self::Error>

Source§

impl Pow<u128> for Complex<f64>

Source§

fn pow(self, exponent: u128) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, u128>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: u128) -> Result<Self, Self::Error>

Source§

impl Pow<usize> for f64

Source§

fn pow(self, exponent: usize) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<f64, usize>, <f64 as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: usize) -> Result<Self, Self::Error>

Source§

impl Pow<usize> for Complex<f64>

Source§

fn pow(self, exponent: usize) -> Self

Raises th number self to the power exponent.

Source§

type Error = FunctionErrors<PowIntExponentInputErrors<Complex<f64>, usize>, <Complex<f64> as RawScalarTrait>::ValidationErrors>

Source§

fn try_pow(self, exponent: usize) -> Result<Self, Self::Error>

Implementors§

Source§

impl<K: NumKernel> Pow<&RealValidated<K>> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<&RealValidated<K>> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<i8> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<i8> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<i16> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<i16> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<i32> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<i32> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<i64> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<i64> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<i128> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<i128> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<isize> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<isize> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<u8> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<u8> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<u16> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<u16> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<u32> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<u32> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<u64> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<u64> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<u128> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<u128> for RealValidated<K>

Source§

impl<K: NumKernel> Pow<usize> for ComplexValidated<K>

Source§

impl<K: NumKernel> Pow<usize> for RealValidated<K>