varunsrin / rusty_money

Money library for Rust
MIT License
85 stars 32 forks source link

Decimal arithmetic specializations #106

Open obaltzer opened 5 months ago

obaltzer commented 5 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.