3 ms·
Bignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through
by CDSlice 6y ago
Bignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through operator overloading.
[0] https://crates.io/crates/rug https://crates.io/crates/rug
- millstone 6y agoThe operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"): let a = Integer::from(10); let b = a + a;
- smmalis37 6y agolet b = &a + &a; will work, but I agree it's unfortunate that this is necessary.
- pimeys 6y agoThis would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.
- Measter 6y agoThat `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.