Java acosh acosh(double x)

Here you can find the source of acosh(double x)

Description

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

License

Open Source License

Parameter

Parameter Description
x Double whose inverse hyperbolic cosine is desired.

Return

The inverse hyperbolic cosine of x.

If x is NaN or less than one, the result is NaN.

This method is a modified version of the one in the Visual Numerics Sfun class.

Declaration


public static double acosh(double x) 

Method Source Code

//package com.java2s;
/*   Please see the license information in the header below. */

public class Main {
    /**   Return the inverse (arc) hyperbolic cosine of a double.
     *//from www .jav  a 2s . c  om
     *   @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

  1. acosh(double a)
  2. acosh(double x)
  3. acosh(double x)
  4. acosh(double x)