Open Light-Wizzard opened 5 years ago
Hey! Thanks for using it. For so large numbers, I guess we can add an implementation using the new BigInt type to get a more precise result.
(BigInt(2418280722821075071453596951) * BigInt(666)) / (BigInt(10000000000000) / BigInt(1)) === 161057496139883599n
I can not get BigInt to work in Qt Qml JavaScript, it does not use the same Engine as the Web, and BigInt uses "this" and Qml JavaScript engine has issues with "this", your code works great for most uses, its only large numbers, when you do your division, the result has the same issue, its wrong, because FP can not handle that size of a number, I thought about breaking the number down and doing the math in smaller increments to see if I can get around this large number issue, it is not your math, it is right, do it by hand, it is the FP rounding it, and toFixed did not help. I do not know if you use Qt Qml, but you would have to, to figure this out, works great for the Web, I like you approach better than other out there, its clean, easy to understand and it works for the Web. 64 bit Floating Point sucks, 128 bit is much better, I had no luck with a long double, knowing they are the same on most devices, it is a moot point, I use this in Felgo for cross Platform use and Android and IoS, so the code has to work on those devices as well.
To fix your code, you would need to find another way to divide the numbers without precision lost.
Great job, one problem with JavaScript and Floating point:
Example: multiply("241828072282107.5071453596951","666") expected value: 161057496139883599.758809556936599999999598382266485785407894582022 returned value: 161057496139883600
(ia ib) / (fa fb) (2418280722821075071453596951 * 666) / (10000000000000 / 1) = 161057496139883599.758809556936599999999598382266485785407894582022 This is what I want it to return, It is not the math that is failing, it is JavaScript, it can not handle this large of Float, so it rounds it toFixed has no effect.
Any idea how to get JavaScript to do this math without Rounding it?