| 269 | } |
| 270 | |
| 271 | inline double erfcinv(double z) { |
| 272 | // |
| 273 | // Begin by testing for domain errors, and other special cases: |
| 274 | // |
| 275 | if ((z < 0) || (z > 2)) |
| 276 | return NAN; |
| 277 | if (z == 0) |
| 278 | return INFINITY; |
| 279 | if (z == 2) |
| 280 | return -INFINITY; |
| 281 | // |
| 282 | // Normalise the input, so it's in the range [0,1], we will |
| 283 | // negate the result if z is outside that range. This is a simple |
| 284 | // application of the erfc reflection formula: erfc(-z) = 2 - erfc(z) |
| 285 | // |
| 286 | double p, q, s; |
| 287 | if (z > 1) { |
| 288 | q = 2 - z; |
| 289 | p = 1 - q; |
| 290 | s = -1; |
| 291 | } else { |
| 292 | p = 1 - z; |
| 293 | q = z; |
| 294 | s = 1; |
| 295 | } |
| 296 | |
| 297 | // |
| 298 | // And get the result, negating where required: |
| 299 | // |
| 300 | return s * erfinv_imp(p, q); |
| 301 | } |
| 302 | |
| 303 | inline double erfinv(double z) { |
| 304 | // |
no test coverage detected