bigeval
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "bigeval", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Mathematical expression solving library", | ||
"main": "BigEval.js", | ||
"scripts": { | ||
"test": "nodeunit tests" | ||
"test": "nodeunit tests/testmain.js tests/testdecimal.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
# BigEval.js | ||
[![Build Status](https://travis-ci.org/aviaryan/BigEval.js.svg?branch=gh-pages)](https://travis-ci.org/aviaryan/BigEval.js) | ||
[![npm](https://img.shields.io/npm/aviaryan/bigeval.svg)]() | ||
[![npm](https://img.shields.io/npm/v/bigeval.svg)]() | ||
[![npm](https://img.shields.io/npm/dm/bigeval.svg)]() | ||
[![npm](https://img.shields.io/npm/l/bigeval.svg)]() | ||
@@ -9,3 +11,3 @@ An alternative to JavaScript's eval() for solving mathematical expressions. It can be extended to use the *Big Number* libraries available to provide results with maximum precision. See [Releases](https://github.com/aviaryan/BigEval.js/releases) for compressed script (~4kb) download. | ||
## Installation | ||
### Installation | ||
@@ -23,3 +25,3 @@ * Node | ||
## Features | ||
### Features | ||
@@ -91,3 +93,3 @@ * Full BODMAS/PEMDAS support (just like `Eval`). | ||
To use decimaljs extension with Node, download the [file](extensions/MikeMcl-decimal.js) and then | ||
``` | ||
```js | ||
var BigEval = require('./MikeMcl-decimal.js'); | ||
@@ -94,0 +96,0 @@ var b = new BigEval(); |
var DecimalBigEval = require('../extensions/MikeMcl-decimal.js'); | ||
var cf = require('./common.js'); | ||
/** | ||
* Function to round (truncate) a string number to certain places | ||
*/ | ||
function roundStr(s, places){ | ||
var posDec = s.indexOf('.'); | ||
if (posDec == -1) | ||
return s; | ||
else { | ||
var sRounded; | ||
if (places <= 0){ | ||
sRounded = s.substr(0, posDec); | ||
} else { | ||
sRounded = s.substr(0, posDec+1+places); | ||
} | ||
return sRounded; | ||
} | ||
} | ||
/** | ||
* Basic tests - simple arithmetic | ||
@@ -41,11 +24,13 @@ */ | ||
testMulDiv: function(test){ | ||
test.equals(roundStr(this.b.exec("345 / 23 * 124 / 41 * 12"), 0), '544'); | ||
test.equals(cf.roundStr(this.b.exec("345 / 23 * 124 / 41 * 12"), 0), '544'); | ||
test.done(); | ||
}, | ||
} | ||
}; | ||
tearDown: function(callback){ | ||
var BigEval = ''; | ||
var DecimalBigEval = ''; | ||
callback(); | ||
} | ||
}; | ||
/** | ||
* Batch auto tests | ||
* @param test | ||
*/ | ||
exports.testBatch = function(test){ | ||
cf.autoTest(test, new DecimalBigEval()); | ||
}; |
var BigEval = require('../BigEval.js'); | ||
var cf = require('./common.js'); | ||
/** | ||
* Function to round (truncate) a string number to certain places | ||
*/ | ||
function roundStr(s, places){ | ||
var posDec = s.indexOf('.'); | ||
if (posDec == -1) | ||
return s; | ||
else { | ||
var sRounded; | ||
if (places <= 0){ | ||
sRounded = s.substr(0, posDec); | ||
} else { | ||
sRounded = s.substr(0, posDec+1+places); | ||
} | ||
return sRounded; | ||
} | ||
} | ||
/** | ||
* Basic tests - simple arithmetic | ||
@@ -41,3 +24,3 @@ */ | ||
testMulDiv: function(test){ | ||
test.equals(roundStr(this.b.exec("345 / 23 * 124 / 41 * 12"), 0), '544'); | ||
test.equals(cf.roundStr(this.b.exec("345 / 23 * 124 / 41 * 12"), 0), '544'); | ||
test.done(); | ||
@@ -47,2 +30,6 @@ } | ||
/** | ||
* test basic expressions | ||
* @param test | ||
*/ | ||
exports.testBasic = function(test){ | ||
@@ -52,2 +39,10 @@ var b = new BigEval(); | ||
test.done(); | ||
}; | ||
/** | ||
* Batch auto tests | ||
* @param test | ||
*/ | ||
exports.testBatch = function(test){ | ||
cf.autoTest(test, new BigEval()); | ||
}; |
32864
10
445
95