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
It looks like Heynote uses floating-point arithmetic to calculate equations with decimal numbers. Instead, it should probably use a library like decimal.js in order to make calculations with decimal numbers precisely.
To Reproduce
Steps to reproduce the behavior:
Open a maths block in Heynote
Type 0.1 + 0.2, and you will see 0.3 displayed. So far so good.
Click on the result 0.3 to copy it, and then paste it into a text editor. You will see 0.30000000000000004. This result is incorrect.
Expected behavior
I expect decimal numbers to be calculated properly, without floating-point errors. (I don't want the result to be merely rounded up or down, I want true decimal mathematics using something like decimal.js).
Version: 1.8.0
The text was updated successfully, but these errors were encountered:
A solution is to limit the precision just below the actual precision of 16 digits in the displayed output
Heynote uses a lower precision for the displayed values in order to look nicer, while the copied result uses the full precision. However, maybe the problem would be mitigated by using a slightly lower precision for the copied result as well?
Math.js uses floating-point arithmetic by default, which is what is causing these imprecise/incorrect results. To get precise and correct results with Math.js, the documentation recommends using Fractions:
Alternatives are to use Fractions which store a number as a numerator and denominator
// Configure the default type of number: 'number' (default), 'BigNumber', or 'Fraction'
math.config({
number: 'Fraction'
})
// use the expression parser
math.evaluate('0.32 + 0.08') // Fraction, 2/5
I presume that you can use the format method to convert the Fraction number to string in decimal format, like "0.3".
It looks like Heynote uses floating-point arithmetic to calculate equations with decimal numbers. Instead, it should probably use a library like decimal.js in order to make calculations with decimal numbers precisely.
To Reproduce
Steps to reproduce the behavior:
0.1 + 0.2
, and you will see0.3
displayed. So far so good.0.3
to copy it, and then paste it into a text editor. You will see0.30000000000000004
. This result is incorrect.Expected behavior
I expect decimal numbers to be calculated properly, without floating-point errors. (I don't want the result to be merely rounded up or down, I want true decimal mathematics using something like decimal.js).
Version: 1.8.0
The text was updated successfully, but these errors were encountered: