Kalk is a math parser library that supports user-defined variables and functions. An example of what it can parse:
f(x, y) = sum(1, 3, (2sin4/x!)^y) + cos(n deg)
a = 3
f(a, 2)
>> 1.1899401098014355
f(x, y) = xy
, x = 5
2sin50 + 2xy
sqrt
and press tab. It will be turned into √
.rust
use kalk::parser;
let mut parser_context = parser::Context::new();
let precision = 53;
let result = parser::eval(&mut parser_context, "5*3", precision).unwrap().unwrap();
assert_eq!(result.to_f64(), 15f64);
The cargo feature rug
enables rug, and is used by default. If you disalbe this, kalk will use f64
instead, making it more portable.
Make sure you have diffutils
gcc
make
and m4
installed.
js
const kalk = await import("@paddim8/kalk");
const context = new kalk.Context();
console.log(context.evaluate("2pi + 3").toScientificNotation().toString());