001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.numbers.gamma;
018
019/**
020 * <a href="https://mathworld.wolfram.com/Erfc.html">Complementary error function</a>.
021 *
022 * <p>\[ \begin{aligned} \operatorname{erfc}(z)
023 *       &amp;= 1 - \operatorname{erf}(z) \\
024 *       &amp;= \frac{2}{\sqrt\pi}\int_z^{\infty} e^{-t^2}\,dt
025 *       \end{aligned} \]
026 */
027public final class Erfc {
028    /** Private constructor. */
029    private Erfc() {
030        // intentionally empty.
031    }
032
033    /**
034     * Returns the complementary error function.
035     *
036     * <p>The value returned is always between 0 and 2 (inclusive).
037     * The appropriate extreme is returned when {@code erfc(x)} is
038     * indistinguishable from either 0 or 2 at {@code double} precision.
039     *
040     * <p>Special cases:
041     * <ul>
042     * <li>If the argument is 0, then the result is 1.
043     * <li>If the argument is {@code > 28}, then the result is 0.
044     * <li>If the argument is {@code < 6}, then the result is 2.
045     * <li>If the argument is nan, then the result is nan.
046     * </ul>
047     *
048     * @param x Value.
049     * @return the complementary error function.
050     */
051    public static double value(double x) {
052        return BoostErf.erfc(x);
053    }
054}