[help] Float Addition
ryanrossiter opened this issue · 4 comments
This is such a basic case that I assume I've just missed something obvious, but I can't seem to get FBig
addition to work.
Here is my test case:
let a = FBig::<Zero, 10>::from(ubig!(10));
let b = FBig::<Zero, 10>::from(ubig!(5));
println!("{} {}", a, b);
println!("{}", a + b);
Which produces:
10 5
10
Even more confusingly, when I change the base to 2 the result becomes 14 (1110
):
let a = FBig::<Zero, 2>::from(ubig!(10));
let b = FBig::<Zero, 2>::from(ubig!(5));
println!("{} {}", a, b);
println!("{}", a + b);
Output:
1010 101
1110
What am I missing here? Thanks in advance
Ah, it seems From<IBig> for FBig
sets the precision to the number of digits in the IBig
, which is applied to the addition, and since 10 only has 1 non-zero digit the precision is 1?
Yes, that's related to the precision. But even in decimal, 10
should have a precision of 2 (two digits). This should be a bug, thanks for reporting this, I will check it later.
I have pushed the fix for this problem. I will try to publish a new version for this in a few days.
A new version of dashu-float
(v0.3.2) is published. Feel free to reopen if the problem still exists.