static public BigDecimal acosh ( final BigDecimal x ) { if ( x . compareTo ( BigDecimal . ONE ) < 0 ) { throw new ArithmeticException ( "Out of range argument cosh " + x . toString ( ) ) ; } else if ( x . compareTo ( BigDecimal . ONE ) == 0 ) { return BigDecimal . ZERO ; } else { BigDecimal xhighpr = scalePrec ( x , 2 ) ; /* arccosh(x) = log(x+sqrt(x^2-1)) */ BigDecimal logx = log ( sqrt ( xhighpr . pow ( 2 ) . subtract ( BigDecimal . ONE ) ) . add ( xhighpr ) ) ; /* The absolute error in arcsinh x is err(x)/sqrt(x^2-1) */ double xDbl = x . doubleValue ( ) ; double eps = 0.5 * x . ulp ( ) . doubleValue ( ) / Math . sqrt ( xDbl * xDbl - 1. ) ; MathContext mc = new MathContext ( err2prec ( logx . doubleValue ( ) , eps ) ) ; return logx . round ( mc ) ; } }
The inverse hyperbolic cosine .