Get around floating point precision of JavaScript fixes #5

Fix `equation` not working on parentheses wrapped variables
Fixed `parseExpression` not working correctly on nested function operators
This commit is contained in:
Mahdi Dibaiee
2015-06-18 15:37:42 +04:30
parent 75969a4e1a
commit 2b3c06c413
6 changed files with 101 additions and 17 deletions

View File

@ -25,6 +25,13 @@ describe('Basic math operators', () => {
it('should work for multi-digit numbers', () => {
expect(M.solve('12+15')).to.equal(27);
});
it('should deal with floating precision of javascript - #5', () => {
expect(M.solve('0.2 + 0.1')).to.equal(0.3);
expect(M.solve('0.2 + 0.4')).to.equal(0.6);
expect(M.solve('round(floor(1.23456789/0.2)) * 0.2')).to.equal(1.2);
expect(M.solve('1.23456789 - (1.23456789 % 0.2)')).to.equal(1.2);
});
});
describe('Negative Numbers', () => {
@ -60,11 +67,11 @@ describe('Precedence', () => {
});
describe('Functions', () => {
it('should work for with parantheses', () => {
it('should work with parantheses', () => {
expect(M.solve('lg(4) * 5')).to.equal(10);
});
it('should work for without parantheses', () => {
it('should work without parantheses', () => {
expect(M.solve('lg4 * 5')).to.equal(10);
});