Skip to content

Instantly share code, notes, and snippets.

@jiggzson
Last active March 12, 2017 03:54
Show Gist options
  • Save jiggzson/df0e9ae8b3b06ff3d8dc2aa062853bd8 to your computer and use it in GitHub Desktop.
Save jiggzson/df0e9ae8b3b06ff3d8dc2aa062853bd8 to your computer and use it in GitHub Desktop.
Erf function using Horner's method
//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 +
t * ( 1.48851587 +
t * (-0.82215223 +
t * ( 0.17087277)))))))))
);
return x >= 0 ? result : -result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment