Crates.io | hyperoperation |
lib.rs | hyperoperation |
version | 0.1.1 |
source | src |
created_at | 2022-12-17 19:04:19.665542 |
updated_at | 2023-04-13 19:09:17.881248 |
description | Hyperoperation (sometimes known as Knuth's notation) calculation library for Rust |
homepage | |
repository | https://github.com/FireFragment/hyperoperation-rs |
max_upload_size | |
id | 740027 |
size | 12,344 |
This crate allows to calculate and format hyperoperation, sometimes known as Knuth's up-arrow notation, which is a way to define very large numbers, such as famous 3↑↑↑3.
Simple calculation:
use hyperoperation::*;
assert_eq!(
hyperoperation::<u64>(&3, 3, 2), // 3 ↑↑ 3
7625597484987
);
Using BigUint to handle big results without overflowing (don't forget to add num_bigint
as your dependency) :
use hyperoperation::*;
use num_bigint::BigUint;
let result = hyperoperation::<BigUint>(&5u8.into(), 3u8.into(), 2); // 5 ↑↑ 3
println!("Result:\n{result}");
assert_eq!(
result % BigUint::from(100_000_000u32),
8203125u32.into()
);
Using Hyperoperation structand formatting it with Knuth's up-arrow notation:
use hyperoperation::*;
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");