-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Suggest removing the code:
return parseFloat(stack[0].value.toFixed(15))
from src/postfix_evaluator.ts
because it only partially solves the issue floating point math, and because there are better work-arounds.
The following code demonstrates both that floating point issues exist, and also that the addToken functionality already allows end-users to fix the issue according to their needs.
import Mexp from './dist/index.js';
import Big from 'big.js';
var mexp = new Mexp();
console.log(mexp.eval('.1 + .2')); // 0.3
console.log(mexp.eval('5.33 + 5.2')); // 10.530000000000001
mexp.addToken([{
type:2,
token:"+",
show:"+",
value:function(a,b){
return Big(a).plus(b).toNumber();
}
}])
console.log(mexp.eval('.1 + .2')); // 0.3
console.log(mexp.eval('5.33 + 5.2')); // 10.53
Metadata
Metadata
Assignees
Labels
No labels