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/Erf.html">Error function</a>.
021 *
022 * <p>\[ \operatorname{erf}(z) = \frac{2}{\sqrt\pi}\int_0^z e^{-t^2}\,dt \]
023 */
024public final class Erf {
025    /** Private constructor. */
026    private Erf() {
027        // intentionally empty.
028    }
029
030    /**
031     * Returns the error function.
032     *
033     * <p>The returned value is always between -1 and 1 (inclusive).
034     * The appropriate extreme is returned when {@code erf(x)} is
035     * indistinguishable from either -1 or 1 at {@code double} precision.
036     *
037     * <p>Special cases:
038     * <ul>
039     * <li>If the argument is 0, then the result is 0.
040     * <li>If the argument is {@code > 6}, then the result is 1.
041     * <li>If the argument is {@code < 6}, then the result is -1.
042     * <li>If the argument is nan, then the result is nan.
043     * </ul>
044     *
045     * @param x the value.
046     * @return the error function.
047     */
048    public static double value(double x) {
049        return BoostErf.erf(x);
050    }
051}