diff --git a/README.md b/README.md index ed45790..9ea3e0a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -numeric.ly.js - an advanced mathematics toolkit for JavaScript and Node.js +Numbers - an advanced mathematics toolkit for JavaScript and Node.js developed by Steve Kaliski, [@sjkaliski](http://twitter.com/sjkaliski) ## Description -Numeric.ly provides a comprehensive set of mathematical tools that currently are not offered in JavaScript. These tools include: +Numbers provides a comprehensive set of mathematical tools that currently are not offered in JavaScript. These tools include: * Basic calculations * Calculus @@ -13,7 +13,7 @@ Numeric.ly provides a comprehensive set of mathematical tools that currently are * Statistics * More... -A few things to note before using: JavaScript, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numeric, you can set an error bound. Anything in this will be considered an "acceptable outcome." +A few things to note before using: JavaScript, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numbers, you can set an error bound. Anything in this will be considered an "acceptable outcome." The primary uses cases are client side operations which the DOM will recognize (e.g. 1.1px == 1px). It can be used for data analysis, calculations, etc. on the server as well. @@ -26,17 +26,18 @@ For example, if we wanted to estimate the integral of sin(x) from -2 to 4, we co Use riemann integrals (with 200 subdivisions) ```javascript +var numbers = require('numbers'); var func = function(x) { return Math.sin(x); } -numeric.calculus.riemann(func, -2, 4, 200); +numbers.calculus.riemann(func, -2, 4, 200); ``` Or adaptive simpson quadrature (with epsilon .0001) ```javascript -numeric.calculus.adaptiveSimpson(func, -2, 4, .0001); +numbers.calculus.adaptiveSimpson(func, -2, 4, .0001); ``` Say we wanted to run some matrix calculations: @@ -47,36 +48,36 @@ We can add two matrices var array1 = [0, 1, 2]; var array2 = [3, 4, 5]; -numeric.matrix.addition(array1, array2); +numbers.matrix.addition(array1, array2); ``` We can transpose a matrix ```javascript -numeric.matrix.transpose(array); +numbers.matrix.transpose(array); ``` Numeric.ly also includes some basic prime number analysis. We can check if a number is prime: ```javascript //basic check -numeric.prime.simple(number); +numbers.prime.simple(number); //elliptic analysis (good for huge numbers) -numeric.prime.elliptic(number); +numbers.prime.elliptic(number); ``` The statistics tools include mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more. ```javascript -numeric.statistic.mean(array); -numeric.statistic.median(array); -numeric.statistic.mode(array); -numeric.statistic.standardDev(array); -numeric.statistic.randomSample(lower, upper, n); -numeric.statistic.correlation(array1, array2); +numbers.statistic.mean(array); +numbers.statistic.median(array); +numbers.statistic.mode(array); +numbers.statistic.standardDev(array); +numbers.statistic.randomSample(lower, upper, n); +numbers.statistic.correlation(array1, array2); ``` -For further documentation, check out our [JSDoc](http://jsdoc.info/sjkaliski/numeric.ly/) +For further documentation, check out our [JSDoc](http://jsdoc.info/sjkaliski/numbers.js/) ## Test diff --git a/index.js b/index.js index 138edd6..f37868c 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports = require('./lib/numeric.js'); +module.exports = require('./lib/numbers.js'); diff --git a/lib/numbers.js b/lib/numbers.js new file mode 100644 index 0000000..07201a9 --- /dev/null +++ b/lib/numbers.js @@ -0,0 +1,32 @@ +/** + * numbers.js + * + * top level management of numbers extensions + * + * (C) 2012 Steve Kaliski + * MIT License + * + */ +var numbers = exports; + + +// Expose methods +numbers.basic = require('./numbers/basic'); +numbers.calculus = require('./numbers/calculus'); +numbers.matrix = require('./numbers/matrix'); +numbers.prime = require('./numbers/prime'); +numbers.statistic = require('./numbers/statistic'); +numbers.useless = require('./numbers/useless'); + +/** + * @property {Number} EPSILON Epsilon (error bound) to be used + * in calculations. Can be set and retrieved freely. + * + * Given the float-point handling by JavaScript, as well as + * the numbersal proficiency of some methods, it is common + * practice to include a bound by which discrepency between + * the "true" answer and the returned value is acceptable. + * + * If no value is provided, 0.001 is default. + */ +numbers.EPSILON = 0.001; diff --git a/lib/numeric/basic.js b/lib/numbers/basic.js similarity index 100% rename from lib/numeric/basic.js rename to lib/numbers/basic.js diff --git a/lib/numeric/calculus.js b/lib/numbers/calculus.js similarity index 97% rename from lib/numeric/calculus.js rename to lib/numbers/calculus.js index a5bb563..51589c3 100644 --- a/lib/numeric/calculus.js +++ b/lib/numbers/calculus.js @@ -1,4 +1,4 @@ -var numeric = require('../numeric'); +var numbers = require('../numbers'); var calculus = exports; @@ -100,7 +100,7 @@ function simpsonRecursive (func, a, b, whole, eps) { * @return {Number} area underneath curve */ calculus.adaptiveSimpson = function (func, a, b, eps) { - eps = (typeof eps === "undefined") ? numeric.EPSILON : eps; + eps = (typeof eps === "undefined") ? numbers.EPSILON : eps; return simpsonRecursive(func, a, b, simpsonDef(func, a, b), eps); }; diff --git a/lib/numeric/matrix.js b/lib/numbers/matrix.js similarity index 100% rename from lib/numeric/matrix.js rename to lib/numbers/matrix.js diff --git a/lib/numeric/prime.js b/lib/numbers/prime.js similarity index 100% rename from lib/numeric/prime.js rename to lib/numbers/prime.js diff --git a/lib/numeric/statistic.js b/lib/numbers/statistic.js similarity index 100% rename from lib/numeric/statistic.js rename to lib/numbers/statistic.js diff --git a/lib/numeric/useless.js b/lib/numbers/useless.js similarity index 100% rename from lib/numeric/useless.js rename to lib/numbers/useless.js diff --git a/lib/numeric.js b/lib/numeric.js deleted file mode 100644 index 7b8c9bd..0000000 --- a/lib/numeric.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * numeric.js - * - * top level management of numeric extensions - * - * (C) 2012 Steve Kaliski - * MIT License - * - */ -var numeric = exports; - - -// Expose methods -numeric.basic = require('./numeric/basic'); -numeric.calculus = require('./numeric/calculus'); -numeric.matrix = require('./numeric/matrix'); -numeric.prime = require('./numeric/prime'); -numeric.statistic = require('./numeric/statistic'); -numeric.useless = require('./numeric/useless'); - -/** - * @property {Number} EPSILON Epsilon (error bound) to be used - * in calculations. Can be set and retrieved freely. - * - * Given the float-point handling by JavaScript, as well as - * the numerical proficiency of some methods, it is common - * practice to include a bound by which discrepency between - * the "true" answer and the returned value is acceptable. - * - * If no value is provided, 0.001 is default. - */ -numeric.EPSILON = 0.001; diff --git a/package.json b/package.json index cf1610e..5212c9d 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "author": "Steve Kaliski (https://github.com/sjkaliski)", - "name": "numeric.ly", - "description": "Advanced mathematics library for JavaScript", + "name": "numbers", + "description": "Advanced Mathematics Library for JavaScript", "version": "0.0.1", - "homepage": "https://github.com/sjkaliski/numeric.ly", + "homepage": "https://github.com/sjkaliski/numbers.js", "repository": { "type": "git", - "url": "git://github.com/sjkaliski/numeric.ly" + "url": "git://github.com/sjkaliski/numbers.js" }, "contributors": [ "David Byrd (https://github.com/davidbyrd11)", @@ -19,7 +19,8 @@ "keywords": [ "math", "mathematics", - "numerical" + "numbers", + "statistics" ], "dependencies": { "mocha": "~1.5.0" diff --git a/test/basic.test.js b/test/basic.test.js index ff4246b..3d9ced8 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,46 +1,46 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var basic = numeric.basic; +var numbers = require('../index.js'); +var basic = numbers.basic; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Standard Mathematics\033[0m'); - // numeric.addition + // numbers.addition test('addition should return the sum of items in an array', function (done) { assert.equal(6, basic.addition([0,1,2,3])); assert.equal(0, basic.addition([0,-3,5,-2])); done(); }); - // numeric.subtraction + // numbers.subtraction test('subtraction should return the difference of items in an array', function (done) { assert.equal(0, basic.subtraction([0,1,2,3])); done(); }); - // numeric.product + // numbers.product test('product should return the product of items in an array', function (done) { assert.equal(24, basic.product([1,2,3,4])); assert.equal(-6, basic.product([-3,2])); done(); }); - // numeric.factorial + // numbers.factorial test('factorial should return the product of n * (n - 1) * (n - 2) * ... * 1', function (done) { assert.equal(24, basic.factorial(4)); assert.equal(120, basic.factorial(5)); done(); }); - // numeric.gcd + // numbers.gcd test('gcd should return the greatest common denominator of two integers', function (done) { assert.equal(6, basic.gcd(1254, 5298)); assert.equal(1, basic.gcd(78699786, 78978965)); done(); }); - // numeric.lcm + // numbers.lcm test('lcm should return the least common multiple of two integers', function (done) { assert.equal(240, basic.lcm(12, 80)); done(); diff --git a/test/calculus.test.js b/test/calculus.test.js index 7747ae9..25b97e1 100644 --- a/test/calculus.test.js +++ b/test/calculus.test.js @@ -1,8 +1,8 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var calculus = numeric.calculus; +var numbers = require('../index.js'); +var calculus = numbers.calculus; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Calculus Mathematics\033[0m'); @@ -13,7 +13,7 @@ suite('numeric', function() { var res = calculus.pointDiff(func, 5); - assert.equal(true, 2 - res < numeric.EPSILON); + assert.equal(true, 2 - res < numbers.EPSILON); done(); }); @@ -35,7 +35,7 @@ suite('numeric', function() { var res = calculus.adaptiveSimpson(func, 0, 100); - assert.equal(true, res - numeric.EPSILON < 666666.66667 < res + numeric.EPSILON); + assert.equal(true, res - numbers.EPSILON < 666666.66667 < res + numbers.EPSILON); done(); }); @@ -46,7 +46,7 @@ suite('numeric', function() { var res = calculus.limit(func, 10, 'middle'); - assert.equal(true, res - numeric.EPSILON < 91.29 < res + numeric.EPSILON); + assert.equal(true, res - numbers.EPSILON < 91.29 < res + numbers.EPSILON); done(); }); diff --git a/test/matrix.test.js b/test/matrix.test.js index dfa5764..00632d0 100644 --- a/test/matrix.test.js +++ b/test/matrix.test.js @@ -1,8 +1,8 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var matrix = numeric.matrix; +var numbers = require('../index.js'); +var matrix = numbers.matrix; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Matrix Mathematics\033[0m'); diff --git a/test/prime.test.js b/test/prime.test.js index 2d132da..a474262 100644 --- a/test/prime.test.js +++ b/test/prime.test.js @@ -1,8 +1,8 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var prime = numeric.prime; +var numbers = require('../index.js'); +var prime = numbers.prime; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Prime Number Mathematics\033[0m'); diff --git a/test/statistic.test.js b/test/statistic.test.js index 1ebf92c..999a13a 100644 --- a/test/statistic.test.js +++ b/test/statistic.test.js @@ -1,8 +1,8 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var statistic = numeric.statistic; +var numbers = require('../index.js'); +var statistic = numbers.statistic; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Statistics Mathematics\033[0m'); @@ -41,7 +41,7 @@ suite('numeric', function() { test('should return the standard deviation of an array of numbers', function(done) { var res = statistic.standardDev([-5, -4, -1, 0, 5, 100]); - assert.equal(true, res - numeric.EPSILON < 37.777 < res + numeric.EPSILON); + assert.equal(true, res - numbers.EPSILON < 37.777 < res + numbers.EPSILON); done(); }); diff --git a/test/useless.test.js b/test/useless.test.js index df6053d..eeab4b6 100644 --- a/test/useless.test.js +++ b/test/useless.test.js @@ -1,12 +1,12 @@ var assert = require('assert'); -var numeric = require('../index.js'); -var useless = numeric.useless; +var numbers = require('../index.js'); +var useless = numbers.useless; -suite('numeric', function() { +suite('numbers', function() { console.log('\n\n\033[34mTesting Useless Mathematics\033[0m'); - //numeric.useless.collatz + //numbers.useless.collatz test('collatz should populate the given array with a collatz sequence', function (done) { var result = []; useless.collatz(7, result);