2 个版本
0.1.1 | 2023 年 4 月 13 日 |
---|---|
0.1.0 | 2022 年 12 月 17 日 |
#1579 in 数学
11KB
88 行
超运算
此 crate 允许计算和格式化 超运算,有时称为 Knuth 上箭头符号,这是一种定义非常大的数字的方法,例如著名的 3↑↑↑3。
功能
示例
简单计算
use hyperoperation::*;
assert_eq!(
hyperoperation::<u64>(&3, 3, 2), // 3 ↑↑ 3
7625597484987
);
使用 BigUint 处理大结果而不会溢出(不要忘记将 num_bigint
作为你的依赖项添加)
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()
);
使用 Hyperoperation 结构体 并使用 Knuth 上箭头符号 格式化它
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");
依赖项
~230KB