ExpressAsPower

Trait ExpressAsPower 

Source
pub trait ExpressAsPower: Sized {
    // Required method
    fn express_as_power(&self) -> Option<(Self, u64)>;
}
Expand description

A trait for expessing as number as the power of some number raised to an exponent greater than 1, if such a representation exists.

Required Methods§

Source

fn express_as_power(&self) -> Option<(Self, u64)>

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 ExpressAsPower for i8

Source§

fn express_as_power(&self) -> Option<(i8, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for i16

Source§

fn express_as_power(&self) -> Option<(i16, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for i32

Source§

fn express_as_power(&self) -> Option<(i32, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for i64

Source§

fn express_as_power(&self) -> Option<(Self, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for i128

Source§

fn express_as_power(&self) -> Option<(Self, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for isize

Source§

fn express_as_power(&self) -> Option<(Self, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for u8

Source§

fn express_as_power(&self) -> Option<(u8, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for u16

Source§

fn express_as_power(&self) -> Option<(u16, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for u32

Source§

fn express_as_power(&self) -> Option<(u32, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for u64

Source§

fn express_as_power(&self) -> Option<(u64, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for u128

Source§

fn express_as_power(&self) -> Option<(Self, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).
Source§

impl ExpressAsPower for usize

Source§

fn express_as_power(&self) -> Option<(Self, u64)>

Expresses a number as a perfect power, if such a representation exists. We define a perfect power as any number of the form $a^x$ where $x > 1$, with $a$ and $x$ both integers. In particular, 0 and 1 are considered perfect powers. If a number has more than one representation as a power, the representation with the smallest base is returned. For example, $64=2^6=4^3=8^2$, but this function returns (2,6) rather than (4,3) or (8,2).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§Notes
  • This returns an Option which is either Some((base, exp)) if the input is a perfect power equal to $\text{base}^\text{exp}$, otherwise None.
  • For 0 this returns Some((0, 2)) and for 1 this returns Some((1, 2)).

Implementors§