Last active
March 12, 2017 03:54
-
-
Save jiggzson/df0e9ae8b3b06ff3d8dc2aa062853bd8 to your computer and use it in GitHub Desktop.
Erf function using Horner's method
This file contains 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 + | |
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