numbat
numbat copied to clipboard
Use high-precision numeric type
https://crates.io/crates/rug (LGPL! Possible to compile to WASM?) Simply use f64 or something like f128? => we could put numeric values on the stack
https://docs.rs/num-rational/latest/num_rational/struct.Ratio.html
https://docs.rs/bigdecimal/0.3.0/bigdecimal/ => any way we can do trigonometry with this?
A feasible option might be to use f64 for floating point and num_bigint/num_rational for integers, rationals.
https://github.com/stencillogic/astro-float
or maybe https://crates.io/crates/num-bigfloat is enough. see also: https://github.com/stencillogic/bigfloat-bench
Whatever we use (if we don't stay with f64
), we need to make sure that it supports all operations that we need (various mathematical functions, pretty-printing, etc).
https://crates.io/crates/rug (LGPL! Possible to compile to WASM?)
We can use Rug just fine (even with our Apache 2.0/MIT license); the only thing is that a compiled Numbat binary including Rug would, as a whole, be licensed under the LGPL instead of Apache 2.0/MIT. In other words, Numbat's source code can stay licensed as-is but Numbat binaries would be under the LGPL, so we'll still be free to move to something else in the future without any permanent repercussions.
Maybe you already knew that, but I just wanted to point it out for you in case you didn't. :)
Beyond the licensing concerns around rug, I'm not sure how easy it would be to compile to WASM.
I've used qd for this purpose for some personal projects in the past.
Positives:
- Pure Rust (easy to target WASM reliably)
- Includes all elementary functions
- MIT license
Negatives:
- Single author; hasn't been updated recently and it's not on crates.io (you have to build against Git).
- No special functions. Those would need to be manually implemented. Not sure if this is currently used by Numbat, but it could be useful in the future and using standard number types means that special functions crates are available.
- Finite precision
- Not sure about conformance testing/correctness
On the other hand, thanks to being pure Rust and MIT-licensed, it could be easy to adopt this as a community project and make any changes required for Numbat. I don't really have numerics chops, but this would be an interesting project. Tagging @Barandis.
(By the way, I really appreciate the rewrite of Insect into Rust! I wanted to contribute previously but was hung up by PureScript.)
Some bigint libraries are listed here: https://github.com/tczajka/bigint-benchmark-rs