Java's BigDecimal for Rust?

I need to implement the log gamma function just as numpy does: https://github.com/numpy/numpy/blob/158159d43a988ff418df5aee3c8b3ecfcb1d0986/numpy/random/src/legacy/legacy-distributions.c#L292 but for big integers/big decimals, just like Java's BigInteger/BigDecimal.

What would be the best rust crate for such thing? I found https://github.com/rust-num/num but this looks like it's just for traits.

I also found https://github.com/akubera/bigdecimal-rs 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.