Hi,
I found an issue I want to highlight, curious about the position of the maintainer of this library on it.
I found that for bigdenary (100 / 3) * 3 != 100 and (100 / 3) + (100 / 3) + (100 / 3) != 100
the failing test are the following
Deno.test("BigDenary: (100 / 3) + (100 / 3) + (100 / 3) == 100", () => {
const b_d100 = new BigDenary(100);
const b_d33 = b_d100.div(3);
const b_d100sum = new BigDenary(0).add(b_d33).add(b_d33).add(b_d33);
assert(b_d100.eq(b_d100sum));
});
Deno.test("BigDenary: (100 / 3) * 3 == 100", () => {
const b_d100 = new BigDenary(100);
const b_d100mul = new BigDenary(100).div(3).mul(3);
assert(b_d100.eq(b_d100mul));
});
The tests succeed when a BigDenary is converted to number with valueOf(), because valueOf() internally convert to string and then uses parseFloat() for the conversion to number, and because the converted string has more than 14 decimals, the returned number is rounded.
I decided then to test also decimal.js and number object, and I found that: number process them correctly (failing on others) while decimal.js fails at them as this library.
Test file attached.
For completeness, I also tested C #, and using the decimal type the problem is not present:
decimal d100 = 100;
decimal d33 = d100/ 3;
decimal d100sum = d33 + d33 + d33;
decimal d100mul = d33 * 3;
Console.WriteLine(d33);
Console.WriteLine(d100 == d100sum);
Console.WriteLine(d100sum);
Console.WriteLine(d100 == d100mul);
Console.WriteLine(d100mul);
test.txt
Hi,
I found an issue I want to highlight, curious about the position of the maintainer of this library on it.
I found that for bigdenary
(100 / 3) * 3 != 100and(100 / 3) + (100 / 3) + (100 / 3) != 100the failing test are the following
The tests succeed when a BigDenary is converted to number with
valueOf(), becausevalueOf()internally convert to string and then usesparseFloat()for the conversion to number, and because the converted string has more than 14 decimals, the returned number is rounded.I decided then to test also decimal.js and
numberobject, and I found that:numberprocess them correctly (failing on others) whiledecimal.jsfails at them as this library.Test file attached.
For completeness, I also tested C #, and using the
decimaltype the problem is not present:test.txt