You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want lib for monetary calculations. decimal-rs sometimes lose precision, and I don't like that. For example, 1.0000000000000000000000000001 * 1.0000000000000000000000000001 is 1.0000000000000000000000000002 under decimal-rs (this is incorrect from mathematical point of view). (I used 0.1.36.) Even checked_mul gives same answer instead of returning error. I want some function (say, exact_mul and similar names for addition and subtraction), which returns Ok (or Some) when a result can be exactly represented and Err (or None) if not.
In my program (assuming my program is bug-free) such precision losing should never happen. But as we all know we can never be sure that there is no bugs! So I want this exact_mul. I would replace my checked_mul with exact_mul (with unwrap). And if I ever lose precision, I will discover this, because I will see panic
The text was updated successfully, but these errors were encountered:
safinaskar
changed the title
I want arithmetic ops which never lose precision
I want arithmetic ops which return error instead of losing precision
May 5, 2022
decimal-rs has 38 digits of precision, and the decimal will be rounded if it overflowed. This is a feature of decimal-rs and we have no plan to add exact_mul.
P.S.: pgnumeric has upto 1000 digits of precision, and 1.0000000000000000000000000001 * 1.0000000000000000000000000001 is 1.00000000000000000000000000020000000000000000000000000001.
I want lib for monetary calculations. decimal-rs sometimes lose precision, and I don't like that. For example,
1.0000000000000000000000000001 * 1.0000000000000000000000000001
is1.0000000000000000000000000002
under decimal-rs (this is incorrect from mathematical point of view). (I used 0.1.36.) Evenchecked_mul
gives same answer instead of returning error. I want some function (say,exact_mul
and similar names for addition and subtraction), which returns Ok (or Some) when a result can be exactly represented and Err (or None) if not.In my program (assuming my program is bug-free) such precision losing should never happen. But as we all know we can never be sure that there is no bugs! So I want this
exact_mul
. I would replace mychecked_mul
withexact_mul
(withunwrap
). And if I ever lose precision, I will discover this, because I will see panicThere is similar bug in rust-decimal paupino/rust-decimal#515
The text was updated successfully, but these errors were encountered: