numbat icon indicating copy to clipboard operation
numbat copied to clipboard

Use high-precision numeric type

Open sharkdp opened this issue 2 years ago • 9 comments

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

sharkdp avatar Sep 04 '22 13:09 sharkdp

https://docs.rs/num-rational/latest/num_rational/struct.Ratio.html

sharkdp avatar Sep 09 '22 22:09 sharkdp

https://docs.rs/bigdecimal/0.3.0/bigdecimal/ => any way we can do trigonometry with this?

sharkdp avatar Oct 08 '22 19:10 sharkdp

A feasible option might be to use f64 for floating point and num_bigint/num_rational for integers, rationals.

sharkdp avatar Oct 08 '22 19:10 sharkdp

https://github.com/stencillogic/astro-float

sharkdp avatar Jul 04 '23 12:07 sharkdp

or maybe https://crates.io/crates/num-bigfloat is enough. see also: https://github.com/stencillogic/bigfloat-bench

sharkdp avatar Jul 04 '23 12:07 sharkdp

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).

sharkdp avatar Jul 12 '23 20:07 sharkdp

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. :)

triallax avatar Aug 23 '23 21:08 triallax

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.)

bsidhom avatar Feb 21 '24 00:02 bsidhom

Some bigint libraries are listed here: https://github.com/tczajka/bigint-benchmark-rs

sharkdp avatar Apr 27 '24 13:04 sharkdp