cmpute/dashu

Different behavior of RBig + IBig and RBig * IBig

spquix opened this issue · 2 comments

It seems when RBig is multiplied by IBig it's truncated to whole number whereas sum or RBig and IBig is computed as rational.
--- multiplication ---
RBig(3 / 7) * IBig(7) = 0 != RBig(3 / 7) * RBig(7 / 1) = 3
RBig(8 / 7) * IBig(7) = 7 != RBig(8 / 7) * RBig(7 / 1) = 8
RBig(1 / 2) * IBig(8) = 0 != RBig(1 / 2) * RBig(8 / 1) = 4
RBig(5 / 2) * IBig(4) = 8 != RBig(5 / 2) * RBig(4 / 1) = 10
--- addition ---
RBig(3 / 7) + IBig(1) = 10/7 == RBig(3 / 7) + RBig(1 / 1) = 10/7
RBig(8 / 7) + IBig(1) = 15/7 == RBig(8 / 7) + RBig(1 / 1) = 15/7
RBig(1 / 2) + IBig(8) = 17/2 == RBig(1 / 2) + RBig(8 / 1) = 17/2
RBig(5 / 2) + IBig(4) = 13/2 == RBig(5 / 2) + RBig(4 / 1) = 13/2

test.txt

Thanks for reporting this! It turns out that it's due to a bug in the multiplication. This bug does not exist for the relaxed type. I will push a fix soon.

The fix has been pushed as a new dashu-ratio version (v0.3.2). Feel free to reopen it if the issue still exists!