Java's BigDecimal for Rust?

I need to implement the log gamma function just as numpy does: numpy/legacy-distributions.c at 158159d43a988ff418df5aee3c8b3ecfcb1d0986 · numpy/numpy · GitHub but for big integers/big decimals, just like Java's BigInteger/BigDecimal.

What would be the best rust crate for such thing? I found GitHub - rust-num/num: A collection of numeric types and traits for Rust. but this looks like it's just for traits.

I also found GitHub - akubera/bigdecimal-rs: Arbitrary precision decimal crate for Rust which does BigDecimal but then I cannot convert to BigInteger when needed because this only supports BigDecimal

1 Like

A BigDecimal can trivially represent a big integer. But there's also the num_bigint crate which only works with integers.

yes, but what should I use for BigDecimal?

You linked to the bigdecimal crate yourself; that should be fine.

even if performance is critical?

I don't see other options. Do you know something better to do very fast math on Rust for big decimals?

What gmp-mpfr-sys about https://crates.io/crates/gmp-mpfr-sys?

Presumably performance is assured as it is a binding the the very fast GNU arbitrary-precision libraries.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.