Skip to content

Commit

Permalink
Added scientific mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Feb 8, 2013
1 parent e1dc475 commit 6ef7f11
Show file tree
Hide file tree
Showing 4 changed files with 1,218 additions and 225 deletions.
Binary file modified calc.jar
Binary file not shown.
25 changes: 25 additions & 0 deletions src/main/java/com/github/calc/BigDecimalUtil.java
Expand Up @@ -19,6 +19,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

/**
* BigDecimal utilities.
Expand All @@ -28,6 +29,9 @@
*/
public final class BigDecimalUtil {
private static final int SCALE = 18;
public static long ITER = 1000;
public static MathContext context = new MathContext( 100 );

private BigDecimalUtil() {
}

Expand Down Expand Up @@ -64,4 +68,25 @@ public static BigDecimal sqrt(BigDecimal x) {

return new BigDecimal(ix, SCALE);
}

public static BigDecimal ln(BigDecimal x) {
if (x.equals(BigDecimal.ONE)) {
return BigDecimal.ZERO;
}

x = x.subtract(BigDecimal.ONE);
BigDecimal ret = new BigDecimal(ITER + 1);
for (long i = ITER; i >= 0; i--) {
BigDecimal N = new BigDecimal(i / 2 + 1).pow(2);
N = N.multiply(x, context);
ret = N.divide(ret, context);

N = new BigDecimal(i + 1);
ret = ret.add(N, context);

}

ret = x.divide(ret, context);
return ret;
}
}

0 comments on commit 6ef7f11

Please sign in to comment.