Struct Hyperoperation

Source
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 duplicate of the value. Read more
1.0.0 · Source§

const 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> Freeze for Hyperoperation<Num>
where Num: Freeze,

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.