Java examples for java.lang:Math Trigonometric Function
Returns the hyperbolic sine of a double.
/*//www. j a v a2 s . c om * ------------------------------------------------------------------------= * 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 licenses 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 { private static final double SINH_COEF[] = { 0.1730421940471796, 0.08759422192276048, 0.00107947777456713, 0.00000637484926075, 0.00000002202366404, 0.00000000004987940, 0.00000000000007973, 0.00000000000000009 }; /** * Returns the hyperbolic sine of a double. * * @param x * A double value. * @return The arc hyperbolic sine of x. If x is NaN or less than one, the * result is NaN. */ static public double sinh(double x) { double ans; double y = Math.abs(x); if (Double.isNaN(x)) { ans = Double.NaN; } else if (Double.isInfinite(y)) { return x; } else if (y < 2.58096e-08) { // 2.58096e-08 = Math.sqrt(6.0*EPSILON_SMALL) ans = x; } else if (y <= 1.0) { ans = x * (1.0 + csevl(2.0 * x * x - 1.0, SINH_COEF)); } else { y = Math.exp(y); if (y >= 94906265.62) { // 94906265.62 = 1.0/Math.sqrt(EPSILON_SMALL) ans = sign(0.5 * y, x); } else { ans = sign(0.5 * (y - 1.0 / y), x); } } return ans; } static double csevl(double x, double coef[]) { double b0, b1, b2, twox; int i; b1 = 0.0; b0 = 0.0; b2 = 0.0; twox = 2.0 * x; for (i = coef.length - 1; i >= 0; i--) { b2 = b1; b1 = b0; b0 = twox * b1 - b2 + coef[i]; } return 0.5 * (b0 - b2); } static private double sign(double x, double y) { double abs_x = ((x < 0) ? -x : x); return (y < 0.0) ? -abs_x : abs_x; } }