pub struct Hyperoperation<Num: NumForKnuth> {
    pub num_a: Num,
    pub num_b: Num,
    pub arrows: u8,
}
Expand description

Representation of Hyperoperation

Features

  • Evaluate the operation with evaluate
  • Format it with the Knuth’s up-arrow notation

Example

Evaluating hyperoperation and formatting it with Knuth’s up-arrow notation:

let expr = Hyperoperation::<u64>::new(3, 3, 2); // Represents 3 ↑↑ 3
let result = expr.clone().evaluate(); // Calculate the value of 3 ↑↑ 3

println!("{expr} = {result}");
assert_eq!(result, 7625597484987);
assert_eq!(format!("{expr}"), "3 ↑↑ 3");

Fields§

§num_a: Num

The first number, before the arrows in Knuth’s up-arrow notation

§num_b: Num

The second numer, after the arrows in Knuth’s up-arrow notation

§arrows: u8

Number of arrows in Knuth’s up-arrow notation

Implementations§

source§

impl<Num: NumForKnuth> Hyperoperation<Num>

source

pub fn evaluate(self) -> Num

Calculates the value of the operation.

Please keep in mind, that for some expressions (like 3 ↑↑↑ 3), this could take a lot of time and/or overflow the value.
To correctly handle large results, it’s recommended to use BigUint as Num.

Panics

In debug mode, the result might overflow Num’s capacity. In release mode, it might silently overflow!

Example
let expr = Hyperoperation::<u64>::new(3, 3, 2); // Represents 3 ↑↑ 3
assert_eq!(expr.evaluate(), 7625597484987);
source

pub fn new(num_a: Num, num_b: Num, arrows: u8) -> Self

Shorthand for initializing the struct

Trait Implementations§

source§

impl<Num: Clone + NumForKnuth> Clone for Hyperoperation<Num>

source§

fn clone(&self) -> Hyperoperation<Num>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Num: Display + NumForKnuth> Display for Hyperoperation<Num>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format the expression as Knuth’s notation

Example
assert_eq!(
    format!("{}", Hyperoperation::<u32> {num_a: 3, num_b: 4, arrows: 2}),
    String::from("3 ↑↑ 4")
)

Auto Trait Implementations§

§

impl<Num> RefUnwindSafe for Hyperoperation<Num>where Num: RefUnwindSafe,

§

impl<Num> Send for Hyperoperation<Num>where Num: Send,

§

impl<Num> Sync for Hyperoperation<Num>where Num: Sync,

§

impl<Num> Unpin for Hyperoperation<Num>where Num: Unpin,

§

impl<Num> UnwindSafe for Hyperoperation<Num>where Num: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.