varunsrin / rusty_money

Money library for Rust
MIT License
93 stars 34 forks source link

Decimal arithmetic specializations #106

Open obaltzer opened 9 months ago

obaltzer commented 9 months ago

The conversion to and from string for arithmetic operations between Money and Decimal are unnecessary and expensive:

test money::tests::bench_decimal_direct      ... bench:           3 ns/iter (+/- 0)
test money::tests::bench_decimal_from_string ... bench:          34 ns/iter (+/- 0)

I am proposing to implement the specializations for Decimal directly.

This PR also removes invalid arithmetic operations such as scalar divided by Money as we don't have reciprocal currency and adds Money / Money = Decimal.