Compute a polynomial approximation of the error function. Precondition: abs(x) <= 1. Otherwise, use ErfcImpl. This follows Cephes's f32 implementation of erf.
| 204 | // |
| 205 | // This follows Cephes's f32 implementation of erf. |
| 206 | static XlaOp ErfImpl32(XlaOp x) { |
| 207 | // Coefficients for by erf(f32), from Cephes. |
| 208 | // |
| 209 | // erf(x) = x P(x^2), 0 < x < 1 |
| 210 | static const std::array<float, 7> kErfTCoefficient{ |
| 211 | +7.853861353153693E-5, -8.010193625184903E-4, +5.188327685732524E-3, |
| 212 | -2.685381193529856E-2, +1.128358514861418E-1, -3.761262582423300E-1, |
| 213 | +1.128379165726710E+0, |
| 214 | }; |
| 215 | return x * EvaluatePolynomial<float>(x * x, kErfTCoefficient); |
| 216 | } |
| 217 | |
| 218 | static XlaOp ErfcImpl64(XlaOp x) { |
| 219 | // Coefficients for erfc(f64), from Cephes. |