static public BigDecimal powRound ( final BigDecimal x , final int n ) { /* The relative error in the result is n times the relative error in the input. * The estimation is slightly optimistic due to the integer rounding of the logarithm. */ MathContext mc = new MathContext ( x . precision ( ) - ( int ) Math . log10 ( ( double ) ( Math . abs ( n ) ) ) ) ; return x . pow ( n , mc ) ; }
Raise to an integer power and round .