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

Java examples for java.lang:Math Trigonometric Function

Description

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

Demo Code

/**   Basic numeric operations not included in standard Java run-time library.
 *
 *   <p>/*  w w  w  . ja  v  a2 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.
 *
 * -------------------------------------------------------------------------
 */

public class Main{
    public static void main(String[] argv) throws Exception{
        double x = 2.45678;
        System.out.println(asinh(x));
    }
    private static final double ASINH_COEF[] = {
            -.12820039911738186343372127359268e+0,
            -.58811761189951767565211757138362e-1,
            .47274654322124815640725249756029e-2,
            -.49383631626536172101360174790273e-3,
            .58506207058557412287494835259321e-4,
            -.74669983289313681354755069217188e-5,
            .10011693583558199265966192015812e-5,
            -.13903543858708333608616472258886e-6,
            .19823169483172793547317360237148e-7,
            -.28847468417848843612747272800317e-8,
            .42672965467159937953457514995907e-9,
            -.63976084654366357868752632309681e-10,
            .96991686089064704147878293131179e-11,
            -.14844276972043770830246658365696e-11,
            .22903737939027447988040184378983e-12,
            -.35588395132732645159978942651310e-13,
            .55639694080056789953374539088554e-14,
            -.87462509599624678045666593520162e-15,
            .13815248844526692155868802298129e-15,
            -.21916688282900363984955142264149e-16,
            .34904658524827565638313923706880e-17 };
    /**   Return the inverse (arc) hyperbolic sine of a double.
     *
     *   @param   x   The value whose inverse hyperbolic sine is desired.
     *
     *   @return      The inverse hyperbolic sine 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>
     */

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

        double y = Math.abs(x);

        if (Double.isNaN(x)) {
            ans = Double.NaN;
        }
        // 1.05367e-08 = Math.sqrt(EPSILON_SMALL)

        else if (y <= 1.05367e-08) {
            ans = x;
        } else if (y <= 1.0D) {
            ans = x
                    * (1.0D + Polynomial.evaluateChebyschev(ASINH_COEF,
                            2.0D * x * x - 1.0D));
        }
        // 94906265.62 = 1/Math.sqrt(EPSILON_SMALL)

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

        if (x < 0.0D)
            ans = -ans;

        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