Struct hyperoperation::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>
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 copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more