Return the inverse (arc) hyperbolic cosine of a double. - Java java.lang

Java examples for java.lang:Math Trigonometric Function

Description

Return the inverse (arc) hyperbolic cosine of a double.

Demo Code

/**   Basic numeric operations not included in standard Java run-time library.
 *
 *   <p>/*w w w .  j a  v  a 2  s  . co  m*/
 *   The binomial methods are modified from those in the Colt library.
 *   </p>
 *
 *   <p>
 *   The following methods for trigonometric functions come from the
 *   Sfun class written by Visual Numerics.
 *   </p>
 *
 *   <ul>
 *   <li>acosh</li>
 *   <li>asinh</li>
 *   <li>atanh</li>
 *   <li>cot</li>
 *   <li>cosh</li>
 *   <li>sinh</li>
 *   <li>tanh</li>
 *   </ul>
 *
 *   <p>
 *   These methods are covered by the following license.
 *   </p>
 *
 * -------------------------------------------------------------------------
 *   $Id: Sfun.java,v 1.1.1.1 1999/03/05 21:43:39 brophy Exp $
 * -------------------------------------------------------------------------
 * Copyright (c) 1997 - 1998 by Visual Numerics, Inc. All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software is freely
 * granted by Visual Numerics, Inc., provided that the copyright notice
 * above and the following warranty disclaimer are preserved in human
 * readable form.
 *
 * Because this software is licensed free of charge, it is provided
 * "AS IS", with NO WARRANTY.  TO THE EXTENT PERMITTED BY LAW, VNI
 * DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * VNI WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE
 * OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * -------------------------------------------------------------------------
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double x = 2.45678;
        System.out.println(acosh(x));
    }

    /**   Return the inverse (arc) hyperbolic cosine of a double.
     *
     *   @param   x   Double whose inverse hyperbolic cosine is desired.
     *
     *   @return      The inverse hyperbolic cosine of x.
     *
     *   <p>
     *   If x is NaN or less than one, the result is NaN.
     *   </p>
     *
     *   <p>
     *   This method is a modified version of the one in the
     *   Visual Numerics Sfun class.
     *   </p>
     */

    public static double acosh(double x) {
        double ans;

        if (Double.isNaN(x) || (x < 1)) {
            ans = Double.NaN;
        }
        // 94906265.62 = 1.0/Math.sqrt(EPSILON_SMALL)

        else if (x < 94906265.62) {
            ans = safeLog(x + Math.sqrt(x * x - 1.0D));
        } else {
            ans = 0.69314718055994530941723212145818D + safeLog(x);
        }

        return ans;
    }

    /**   Return natural log of a double.
     *
     *   @param   x   The number whose natural log is desired.
     *
     *   @return      The natural log of x.  If x is zero,
     *            returns 0.
     */

    public static double safeLog(double x) {
        if (x == 0.0D) {
            return 0.0D;
        } else {
            return Math.log(x);
        }
    }
}

Related Tutorials