Skip to content

remove incomplete fix for floating point issues #74

@cmcnulty

Description

@cmcnulty

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions