1public static long ITER = 1000;
2
3 public static BigDecimal cuberoot(BigDecimal b) {
4 // Specify a math context with 40 digits of precision.
5
6 MathContext mc = new MathContext(40);
7
8 BigDecimal x = new BigDecimal("1", mc);
9
10 // Search for the cube root via the Newton-Raphson loop. Output each // successive iteration's value.
11
12 for (int i = 0; i < ITER; i++) {
13 x = x.subtract(
14 x.pow(3, mc)
15 .subtract(b, mc)
16 .divide(new BigDecimal("3", mc).multiply(
17 x.pow(2, mc), mc), mc), mc);
18 }
19 return x;
20 }