Java cosh cosh(double x)

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

Description

Return the hyperbolic cosine of a double.

License

Open Source License

Parameter

Parameter Description
x The value whose hyperbolic cosine is desired.

Return

The hyperbolic cosine of x.

If x is NaN, the result is NaN.

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

Declaration


static public double cosh(double x) 

Method Source Code

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

public class Main {
    /**   Return the hyperbolic cosine of a double.
     *//  w w w  .j  a  va 2 s .com
     *   @param   x   The value whose hyperbolic cosine is desired.
     *
     *   @return      The hyperbolic cosine of x.
     *
     *   <p>
     *   If x is NaN, the result is NaN.
     *   </p>
     *
     *   <p>
     *   This method is a modified version of the one in the
     *   Visual Numerics Sfun class.
     *   </p>
     */

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

        double y = Math.exp(Math.abs(x));

        if (Double.isNaN(x)) {
            ans = Double.NaN;
        } else if (Double.isInfinite(x)) {
            ans = x;
        }
        // 94906265.62 = 1.0/Math.sqrt(EPSILON_SMALL)

        else if (y < 94906265.62D) {
            ans = 0.5D * (y + 1.0D / y);
        } else {
            ans = 0.5D * y;
        }

        return ans;
    }
}

Related

  1. cosh(double paramDouble)
  2. cosh(double x)
  3. cosh(Double x)
  4. cosh(double x)