๐งฎ Rug-Calc
A zero-copy, high-performance evaluator for arbitrary-precision scientific computing. Powered by Rug, it delivers extreme accuracy and numerical stability with minimal memory overhead.
โจ Features
- ๐ High Performance: Features a non-recursive architecture that evaluates expressions in a single traversal, ensuring predictable and blazing-fast execution.
- โ๏ธ Arbitrary Precision: Engineered with 2560-bit internal precision, far exceeding the limitations of standard hardware floats for mission-critical calculations.
- ๐ฆ Zero-Copy & Efficient: Utilizes byte-level scanning and a custom state-machine to minimize memory allocations and CPU overhead during expression parsing.
- ๐งช Rich Mathematical Suite: Supports 40+ built-in functions, including advanced Trigonometry, Gamma, Zeta, Airy, and Error functions.
- ๐ญ Scientific Constants: Instant, high-precision access to fundamental constants: Pi (P), Euler (Y), Catalan (C), and Log2 (L).
- ๐จ Smart Formatting: Provides versatile output options, including fixed-point rounding and "clean" string formatting with support for up to 700 decimal places.
- ๐ก๏ธ Robust Stability: Designed for applications requiring extreme numerical stability and graceful error handling over panics.
๐ Quick Start
Add this to your Cargo.toml:
[]
= "0.1.8"
๐ ๏ธ Supported Syntax
rug_calc utilizes a state-machine parser to handle complex mathematical structures without recursion:
- Basic arithmetic operations:
+,-,*,/,%,^ - Floating-point remainder (fmod):
% - Exponentiation (power):
^ - Unlimited nesting depth for grouped expressions:
(), - Scientific notation:
1.23e-5,1.23E-5,1.23e+5,1.23E5 - Constant Identifiers:
P,Y,C,L
๐ Mathematical Function Support
rug_calc provides a comprehensive suite of high-precision functions powered by the MPFR library.
- Advanced functions:
ai,abs,cos,sin,tan,csc,sec,cot,coth,ceil,cosh,sinh,tanh,sech,ln,csch,acos,asin,atan,acosh,asinh,atanh,log2,log10,sqrt,cbrt,fac,erf,li2,exp,exp2,exp10,eint,zeta,trunc,gamma,floor,frac,sgn,erfc,digamma,recip - Supports scientific notation: Case-insensitive
eorEis supported when preceded by a digit.
๐ Constant Identifiers
To maintain parsing efficiency and avoid ambiguity with functions, constants use single-character uppercase identifiers:
P: Pi constantY: Euler-Mascheroni constantC: Catalanโs constantL: Natural logarithm of 2 (Log2)
๐ก Example Usage
The following example demonstrates how to use.
use Calculator;
let mut calc = new;
// 1. Simple arithmetic with negative results
let result = calc.run.unwrap;
// 2. Scientific Notation (Zero-Copy parsing of 'e')
// Calculates: (1.23*10^-5)*2
let sci_result = calc.run.unwrap;
println!;
// 3. Advanced functions (Calculating cos(sin(ฯ/4)))
let cos_sin_pi_4 = calc.run.unwrap;
// 4. Mixing Scientific Notation with Special Constants
// Calculates: 5.0*10^12 divided by Euler's constant (Y)
let mixed_result = calc.run.unwrap;
// 5. Infinitely nested scientific computing
let expr = "8*6-(cos(6-3*(6/P^2-6)*3)+5)/Y*8";
let complex = calc.run.unwrap;
// 6. High-precision string output (50 decimal places)
let pi_str = calc.run_round.unwrap;
println!;
// 7. Small number formatting from scientific notation
let small_val = calc.run_round.unwrap;
println!; // "0.0000000001"
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub.
License
This project is licensed under the MIT License.