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>
impl<Num: NumForKnuth> Hyperoperation<Num>
Sourcepub fn evaluate(self) -> Num
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);
Trait Implementations§
Source§impl<Num: Clone + NumForKnuth> Clone for Hyperoperation<Num>
impl<Num: Clone + NumForKnuth> Clone for Hyperoperation<Num>
Source§fn clone(&self) -> Hyperoperation<Num>
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)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more