bigeval
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -113,2 +113,3 @@ /* | ||
this.FUNCTION = {}; | ||
this.fallbackToGlobalFunctions = false; | ||
@@ -563,3 +564,3 @@ /** @type function(name:string):any */ | ||
if (!left && op === '-') { | ||
left = [{ type: TokenType.NUMBER, value: 0, source: expression }]; | ||
left = [{ type: TokenType.NUMBER, value: 0, source: '0-', pos: token.pos, end: token.end }]; | ||
} | ||
@@ -636,6 +637,7 @@ else if (!left && op === '+') { | ||
// When we have something like this: "5*-1", we will move the "-" to be part of the number token. | ||
if (token.type === TokenType.NUMBER && | ||
prevToken.type === TokenType.OP && | ||
(prevToken.value === '-' || prevToken.value === '+') && | ||
((i > 1 && tokens[i - 2].type === TokenType.OP) || i === 1) | ||
((i > 1 && tokens[i - 2].type === TokenType.OP && this.suffixOps.indexOf(tokens[i - 2].value) === -1) || i === 1) | ||
) { | ||
@@ -807,3 +809,3 @@ | ||
} | ||
else if (typeof(root[fname]) == 'function') { | ||
else if (this.fallbackToGlobalFunctions && typeof(root[fname]) == 'function') { | ||
return root[fname].apply(root, args); | ||
@@ -810,0 +812,0 @@ } |
{ | ||
"name": "bigeval", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Mathematical expression solving library", | ||
@@ -5,0 +5,0 @@ "main": "BigEval.js", |
@@ -68,3 +68,4 @@ # BigEval.js | ||
BigEval supports functions like sin(), cos() ... When a function is used in an expression, BigEval first looks into its methods to see if such a function exist, then it looks into the JavaScript's **Math** library and in the end it looks into window's global namespace for the function. | ||
BigEval supports functions like sin(), cos() ... When a function is used in an expression, BigEval first looks into its methods to see if such a function exist, then it looks into the JavaScript's **Math** library. | ||
If you want it to fallback into the global namespace (i.e window) when it cannot find a function, you should set `bigEval.fallbackToGlobalFunctions = true;`. | ||
Please note that we use just `sin()` and not `Math.sin()` in expressions. Attaching a new function to BigEval is easy. | ||
@@ -71,0 +72,0 @@ ```javascript |
@@ -28,2 +28,12 @@ var BigEval = require("../BigEval.js"); | ||
testFactorial: function(test){ | ||
test.equals(this.b.exec("2*5!+3"), 243); | ||
test.done(); | ||
}, | ||
testEnclosedNegative: function(test){ | ||
test.equals(Math.round(this.b.exec("(-5)+6")), 1); | ||
test.done(); | ||
}, | ||
testErrorData1: function(test){ | ||
@@ -66,3 +76,3 @@ try { | ||
test.equals(this.b.exec("1e1 + 1e+2 + 1e-3"), 110.001); | ||
test.done(); | ||
test.done(); | ||
}, | ||
@@ -69,0 +79,0 @@ |
41974
902
120