static BigNumber Logarithm(BigNumber y) { // y in ( -0.05-, 0.05+ ), return ln((1+y)/(1-y)) BigNumber v = (new BigNumber("1")), y2 = y * y, t = y2, z = t / (new BigNumber("3")); for (BigNumber i = new BigNumber("3"); CompareNumber.Compare(z, new BigNumber("0")) != 0; z = (t *= y2) / (i += new BigNumber("2"))) { v += z; } return(v * y * (new BigNumber("2"))); }
//判定小于 public static bool operator <(BigNumber x1, BigNumber x2) { if (CompareNumber.Compare(x1, x2) == -1) { return(true); } else { return(false); } }
public static BigNumber Log(BigNumber x) { if (CompareNumber.Compare(x, new BigNumber("0")) == -1 || CompareNumber.Compare(x, new BigNumber("0")) == 0) { throw new ArgumentException("Must be positive"); } int k = 0, l = 0; for (; CompareNumber.Compare(x, new BigNumber("1")) == 1; k++) { x /= new BigNumber("10"); } for (; CompareNumber.Compare(x, new BigNumber("0.1")) == -1; k--) { x *= new BigNumber("10"); // ( 0.1, 1 ] } for (; CompareNumber.Compare(x, new BigNumber("0.9047")) == -1; l--) { x *= new BigNumber("1.2217"); // [ 0.9047, 1.10527199 ) } return(k * ln10 + l * lnr + Logarithm((x - new BigNumber("1")) / (x + new BigNumber("1")))); }
public int CompareTo(BigNumber other) { return(CompareNumber.Compare(this, other)); }