function erfinv( x ) {
	var sign;
	var ax;
	var qs;
	var q;
	var g;
	var r;

	// Special case: NaN
	if ( isnan( x ) ) {
		return NaN;
	}
	// Special case: 1
	if ( x === 1.0 ) {
		return PINF;
	}
	// Special case: -1
	if ( x === -1.0 ) {
		return NINF;
	}
	// Special case: +-0
	if ( x === 0.0 ) {
		return x;
	}
	// Special case: |x| > 1 (range error)
	if ( x > 1.0 || x < -1.0 ) {
		return NaN;
	}
	// Argument reduction (reduce to interval [0,1]). If `x` is negative, we can safely negate the value, taking advantage of the error function being an odd function; i.e., `erf(-x) = -erf(x)`.
	if ( x < 0.0 ) {
		sign = -1.0;
		ax = -x;
	} else {
		sign = 1.0;
		ax = x;
	}
	q = 1.0 - ax;

	// |x| <= 0.5
	if ( ax <= 0.5 ) {
		g = ax * ( ax + 10.0 );
		r = rationalFcnR1( ax );
		return sign * ( (g*Y1) + (g*r) );
	}
	// 1-|x| >= 0.25
	if ( q >= 0.25 ) {
		g = sqrt( -2.0 * ln(q) );
		q -= 0.25;
		r = rationalFcnR2( q );
		return sign * ( g / (Y2+r) );
	}
	q = sqrt( -ln( q ) );

	// q < 3
	if ( q < 3.0 ) {
		qs = q - 1.125;
		r = rationalFcnR3( qs );
		return sign * ( (Y3*q) + (r*q) );
	}
	// q < 6
	if ( q < 6.0 ) {
		qs = q - 3.0;
		r = rationalFcnR4( qs );
		return sign * ( (Y4*q) + (r*q) );
	}
	// q < 18
	qs = q - 6.0;
	r = rationalFcnR5( qs );
	return sign * ( (Y5*q) + (r*q) );
}
Evaluates the inverse error function.

## Method

1.  For \\(|x| \leq 0.5\\), we evaluate the inverse error function using the rational approximation

    ```tex
    \operatorname{erf^{-1}}(x) = x(x+10)(\mathrm{Y} + \operatorname{R}(x))
    ```

    where \\(Y\\) is a constant and \\(\operatorname{R}(x)\\) is optimized for a low absolute error compared to \\(|Y|\\).

    <!-- <note> -->

    Max error \\(2.001849\mbox{e-}18\\). Maximum deviation found (error term at infinite precision) \\(8.030\mbox{e-}21\\).

    <!-- </note> -->

2.  For \\(0.5 > 1-|x| \geq 0\\), we evaluate the inverse error function using the rational approximation

    ```tex
    \operatorname{erf^{-1}} = \frac{\sqrt{-2 \cdot \ln(1-x)}}{\mathrm{Y} + \operatorname{R}(1-x)}
    ```

    where \\(Y\\) is a constant, and \\(\operatorname{R}(q)\\) is optimized for a low absolute error compared to \\(Y\\).

    <!-- <note> -->

    Max error \\(7.403372\mbox{e-}17\\). Maximum deviation found (error term at infinite precision) \\(4.811\mbox{e-}20\\).

    <!-- </note> -->

3.  For \\(1-|x| < 0.25\\), we have a series of rational approximations all of the general form

    ```tex
    p = \sqrt{-\ln(1-x)}
    ```

    Accordingly, the result is given by

    ```tex
    \operatorname{erf^{-1}}(x) = p(\mathrm{Y} + \operatorname{R}(p-B))
    ```

    where \\(Y\\) is a constant, \\(B\\) is the lowest value of \\(p\\) for which the approximation is valid, and \\(\operatorname{R}(x-B)\\) is optimized for a low absolute error compared to \\(Y\\).

    <!-- <note> -->

    Almost all code will only go through the first or maybe second approximation.  After that we are dealing with very small input values.

    -   If \\(p < 3\\), max error \\(1.089051\mbox{e-}20\\).
    -   If \\(p < 6\\), max error \\(8.389174\mbox{e-}21\\).
    -   If \\(p < 18\\), max error \\(1.481312\mbox{e-}19\\).
    -   If \\(p < 44\\), max error \\(5.697761\mbox{e-}20\\).
    -   If \\(p \geq 44\\), max error \\(1.279746\mbox{e-}20\\).

    <!-- </note> -->

    <!-- <note> -->

    The Boost library can accommodate \\(80\\) and \\(128\\) bit long doubles. JavaScript only supports a \\(64\\) bit double (IEEE 754). Accordingly, the smallest \\(p\\) (in JavaScript at the time of this writing) is \\(\sqrt{-\ln(\sim5\mbox{e-}324)} = 27.284429111150214\\).

    <!-- </note> -->

@param {number} x - input value
@returns {number} function value

@example
var y = erfinv( 0.5 );
// returns ~0.4769

@example
var y = erfinv( 0.8 );
// returns ~0.9062

@example
var y = erfinv( 0.0 );
// returns 0.0

@example
var y = erfinv( -0.0 );
// returns -0.0

@example
var y = erfinv( -1.0 );
// returns -Infinity

@example
var y = erfinv( 1.0 );
// returns Infinity

@example
var y = erfinv( NaN );
// returns NaN