Java examples for java.lang:Math Trigonometric Function
Returns the inverse (arc) hyperbolic tangent of a double.
/** Basic numeric operations not included in standard Java run-time library. * * <p>/*w w w . j av a 2s. c o 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(atanh(x)); } private static final double ATANH_COEF[] = { .9439510239319549230842892218633e-1, .4919843705578615947200034576668e-1, .2102593522455432763479327331752e-2, .1073554449776116584640731045276e-3, .5978267249293031478642787517872e-5, .3505062030889134845966834886200e-6, .2126374343765340350896219314431e-7, .1321694535715527192129801723055e-8, .8365875501178070364623604052959e-10, .5370503749311002163881434587772e-11, .3486659470157107922971245784290e-12, .2284549509603433015524024119722e-13, .1508407105944793044874229067558e-14, .1002418816804109126136995722837e-15, .6698674738165069539715526882986e-17, .4497954546494931083083327624533e-18 }; /** Returns the inverse (arc) hyperbolic tangent of a double. * * @param x The value whose inverse hyperbolic tangent is desired. * * @return The arc hyperbolic tangent of x. * * <p> * If x is NaN or |x|>1, 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 atanh(double x) { double ans; double y = Math.abs(x); if (Double.isNaN(x)) { ans = Double.NaN; } // 1.82501e-08 = Math.sqrt(3.0*EPSILON_SMALL) else if (y < 1.82501e-08) { ans = x; } else if (y <= 0.5D) { ans = x * (1.0D + Polynomial.evaluateChebyschev(ATANH_COEF, 8.0D * x * x - 1.0D)); } else if (y < 1.0D) { ans = 0.5D * safeLog((1.0D + x) / (1.0D - x)); } else if (y == 1.0D) { ans = x * Double.POSITIVE_INFINITY; } else { ans = Double.NaN; } 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); } } }