This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the intersection of two arrays | |
* @param a An array | |
* @param b An array | |
* @returns {Array} | |
*/ | |
function intersection(a, b) { | |
b = b.slice(); | |
var c = []; | |
if(a.length > b.length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Ported from: http://stackoverflow.com/questions/457408/is-there-an-easily-available-implementation-of-erf-for-python | |
var erf = function(x) { | |
var t = 1/(1+0.5*Math.abs(x)); | |
var result = 1-t*Math.exp( -x*x - 1.26551223 + | |
t * ( 1.00002368 + | |
t * ( 0.37409196 + | |
t * ( 0.09678418 + | |
t * (-0.18628806 + | |
t * ( 0.27886807 + | |
t * (-1.13520398 + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var defint = function(symbol, dx, from, to) { | |
var vars = core.Utils.variables(symbol), | |
integral = __.integrate(symbol, dx), | |
retval; | |
if(!integral.hasIntegral()) { | |
var upper = {}, | |
lower = {}; | |
upper[dx] = to; | |
lower[dx] = from; | |
retval = _.subtract(_.parse(integral, upper), _.parse(integral, lower)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function F(d) { | |
if(!(this instanceof F)) | |
return new F(d); | |
if(Array.isArray(d)) | |
this.fraction = d; | |
else | |
this.fraction = this.convert(d); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var factorial = function(n) { | |
++n; | |
var r = 1; | |
while(n-->1) | |
r*=n; | |
return r; | |
} | |
var calculatePI = function(n) { | |
n = n || 30; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var factorial = function(n) { | |
if(n === 0) | |
return 1; | |
var f = n; | |
while(n > 1) { | |
f *= --n; | |
} | |
return f; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//TODO: Still depends on Math.sqrt and Math.pow | |
var factorial = function(n) { | |
++n; | |
var r = 1; | |
while(n-->1) | |
r*=n; | |
return r; | |
}; | |
var PI = function(n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sqrt(n) { | |
var xn, d, ld; | |
var c = 0; //counter | |
var done = false; | |
var delta = 1e-17; | |
xn = n/2; | |
var safety = 1000; | |
do { | |
//break if we're not converging | |
if(c > safety) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a number to base 10 give a base and a number array | |
* @param {int[]} n_array | |
* @param {int} base | |
* @returns {int} | |
*/ | |
var to_base10 = function(n_array, base) { | |
n_array.reverse(); | |
var n = 0; | |
for(var i=0, l=n_array.length; i<l; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Javascript has the toExponential method but this allows you to work with string and therefore any number of digits of your choosing | |
* For example Scientific('464589498449496467924197545625247695464569568959124568489548454'); | |
*/ | |
var isInt = function(n) { | |
return n%1 === 0; | |
} | |
var nround = function (x, s) { | |
if (isInt(x)) { | |
if (x >= Number.MAX_VALUE) |