Skip to content

Instantly share code, notes, and snippets.

@camsom
Created October 20, 2014 21:09
Show Gist options
  • Save camsom/0ef5690133ac3a05659e to your computer and use it in GitHub Desktop.
Save camsom/0ef5690133ac3a05659e to your computer and use it in GitHub Desktop.
ERROR_FUNCTION = '''
CREATE OR REPLACE FUNCTION erf(x decimal) RETURNS decimal AS $$
DECLARE a1 decimal = 0.254829592;
DECLARE a2 decimal = -0.284496736;
DECLARE a3 decimal = 1.421413741;
DECLARE a4 decimal = -1.453152027;
DECLARE a5 decimal = 1.061405429;
DECLARE p decimal = 0.3275911;
DECLARE sign integer = 1;
DECLARE t decimal;
DECLARE y decimal;
BEGIN
IF x < 0 THEN
sign := -1;
END IF;
x := @x;
t := 1.0/(1.0 + p*x);
y := 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
RETURN sign*y;
END; $$
LANGUAGE PLPGSQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment