/** * Compute the <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top"> * hyperbolic sine</a> of this complex number. Implements the formula: * * <pre> * <code> * sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)i * </code> * </pre> * * where the (real) functions on the right-hand side are {@link java.lang.Math#sin}, {@link * java.lang.Math#cos}, {@link FastMath#cosh} and {@link FastMath#sinh}. <br> * Returns {@link Complex#NaN} if either real or imaginary part of the input argument is {@code * NaN}. <br> * Infinite values in real or imaginary parts of the input may result in infinite or NaN values * returned in parts of the result. * * <pre> * Examples: * <code> * sinh(1 ± INFINITY i) = NaN + NaN i * sinh(±INFINITY + i) = ± INFINITY + INFINITY i * sinh(±INFINITY ± INFINITY i) = NaN + NaN i * </code> * </pre> * * @return the hyperbolic sine of {@code this}. * @since 1.2 */ public Complex sinh() { if (isNaN) { return NaN; } return createComplex( FastMath.sinh(real) * FastMath.cos(imaginary), FastMath.cosh(real) * FastMath.sin(imaginary)); }
/** * Compute the <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top"> * hyperbolic tangent</a> of this complex number. Implements the formula: * * <pre> * <code> * tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i * </code> * </pre> * * where the (real) functions on the right-hand side are {@link FastMath#sin}, {@link * FastMath#cos}, {@link FastMath#cosh} and {@link FastMath#sinh}. <br> * Returns {@link Complex#NaN} if either real or imaginary part of the input argument is {@code * NaN}. <br> * Infinite values in real or imaginary parts of the input may result in infinite or NaN values * returned in parts of the result. * * <pre> * Examples: * <code> * tanh(a ± INFINITY i) = NaN + NaN i * tanh(±INFINITY + bi) = ±1 + 0 i * tanh(±INFINITY ± INFINITY i) = NaN + NaN i * tanh(0 + (π/2)i) = NaN + INFINITY i * </code> * </pre> * * @return the hyperbolic tangent of {@code this}. * @since 1.2 */ public Complex tanh() { if (isNaN || Double.isInfinite(imaginary)) { return NaN; } if (real > 20.0) { return createComplex(1.0, 0.0); } if (real < -20.0) { return createComplex(-1.0, 0.0); } double real2 = 2.0 * real; double imaginary2 = 2.0 * imaginary; double d = FastMath.cosh(real2) + FastMath.cos(imaginary2); return createComplex(FastMath.sinh(real2) / d, FastMath.sin(imaginary2) / d); }