ecwyne / meteor-mathjs

Mathjs, An extensive math library for JavaScript, packaged for Meteor. See http://mathjs.org.
7 stars 2 forks source link

floating point not fixed #5

Open DiedeGu opened 8 years ago

DiedeGu commented 8 years ago

Hi Ecwyne,

I am using math.js in a package and am writing tests for it. Currently I require the package like this. api.use('ecwyne:mathjs'); . The package works but the two decimal addition tests fail while in the online demo the same addition gives a correct result. Am I using the package in the wrong way / Do I still need to require the mathjs package?

it('eval returns 0.3 for 0.1 + 0.2', function(){ expect(math.eval('0.1 + 0.2')).toBe(0.3); });

it('select returns 0.3 for 0.1 + 0.2', function(){ expect(math.select(0.1).add(0.2).done()).toBe(0.3); });

Thanks in advanced

ecwyne commented 8 years ago

@DiedeGu where are you able to properly evaluate 0.1 + 0.2?

When I go to mathjs.org and evaluate the following in my console:

math.eval('0.1 + 0.2');

it returns 0.30000000000000004 (the expected javascript floating point output) See this cool video about floating point math in javasctipt

ecwyne commented 8 years ago

Also see http://mathjs.org/docs/datatypes/numbers.html#roundoff-errors