static double approx_erfc(double x) {
            double sq = x*x;
            double mult = Math.exp(-sq) / (x * Math.sqrt(Math.PI));
            double term = 1.0;
            long n = 1;
            double sum = 0.0;
            while ((sum + term) != sum) {
                double pterm = term;
                sum += term;
                term = 0.5 * pterm * n / sq;
                if (term > pterm) {
                    sum -= 0.5 * pterm;
                    return sum*mult;
                }
                n += 2;
                pterm = term;
                sum -= term;
                term = 0.5 * pterm * n / sq;
                if (term > pterm) {
                    sum += 0.5 * pterm;
                    return sum*mult;
                }
                n += 2;
            }
            return sum*mult;
        }
Factory of scalar Java functions.
The purpose of this is to embellish anonymous functions with a runtime type
such that they can be inspected and will return a parsable toString.

@author bratseth
vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java