paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
995 stars 181 forks source link

Replace filtery with a strategy for implementation of proptest::Arbitrary #659

Closed uzytkownik closed 3 months ago

uzytkownik commented 3 months ago

Currently the proptest::Arbitrary implementation uses filter_map with failure rate of ~90%. This causes problems if user need to filter it further.

This change replaces it with using a range removing backtracing.

paupino commented 3 months ago

Thank you for this!

For context for those looking into this - the previous implementation was generating a random number for scale however discarding most of them. This is quite inefficient - this updated implementation instead places a range on scale generation so that it can succeed without having to discard items.