// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.math.BigDecimal;
import java.math.BigInteger;

public class LogFun {
    public static BigInteger log10(BigInteger v) {
        return new BigInteger(Integer.toString(v.toString().length() - 1));
    }
    private static BigDecimal TWO = new BigDecimal(2);
    private static BigDecimal LNTWO = new BigDecimal(Math.log(2));
    private static BigDecimal MAXSIMPLE = new BigDecimal(Double.MAX_VALUE);
    public static BigDecimal ln(BigDecimal v) {
        if(v.compareTo(MAXSIMPLE) > 0) {
            return ln(v.divide(TWO)).add(LNTWO);
        } else {
            return new BigDecimal(Math.log(v.doubleValue()));
        }
    }
    public static BigInteger ln(BigInteger v) {
        return ln(new BigDecimal(v)).toBigInteger();
    }
    public static void test(int v) {
        System.out.println(Math.log10(v) + "=" + log10(new BigInteger(Integer.toString(v))));
        System.out.println(Math.log(v) + "=" + ln(new BigInteger(Integer.toString(v))));
    }
    public static void main(String[] args) {
        test(1234567);
        test(100);
        test((int)Math.E);
    }
}
