internal static EInteger FindPowerOfTenFromBig(EInteger bigintExponent) { int sign = bigintExponent.Sign; if (sign < 0) { return(EInteger.Zero); } if (sign == 0) { return(EInteger.One); } if (bigintExponent.CompareTo(ValueBigInt36) <= 0) { return(FindPowerOfTen((int)bigintExponent)); } FastInteger intcurexp = FastInteger.FromBig(bigintExponent); EInteger mantissa = EInteger.One; EInteger bigpow = EInteger.Zero; // DebugUtility.Log("Getting power of ten from big "+bigintExponent); while (intcurexp.Sign > 0) { if (intcurexp.CompareToInt(18) <= 0) { bigpow = FindPowerOfTen(intcurexp.AsInt32()); mantissa *= (EInteger)bigpow; break; } if (intcurexp.CompareToInt(9999999) <= 0) { int val = intcurexp.AsInt32(); bigpow = FindPowerOfFive(val); bigpow <<= val; mantissa *= (EInteger)bigpow; break; } if (bigpow.IsZero) { bigpow = FindPowerOfFive(9999999); bigpow <<= 9999999; } mantissa *= bigpow; intcurexp.AddInt(-9999999); } return(mantissa); }
internal static EInteger FindPowerOfFiveFromBig(EInteger diff) { int sign = diff.Sign; if (sign < 0) { return(EInteger.Zero); } if (sign == 0) { return(EInteger.One); } FastInteger intcurexp = FastInteger.FromBig(diff); if (intcurexp.CompareToInt(54) <= 0) { return(FindPowerOfFive(intcurexp.AsInt32())); } EInteger mantissa = EInteger.One; EInteger bigpow; EInteger origdiff = diff; bigpow = ValuePowerOfFiveCache.GetCachedPower(origdiff); if (bigpow != null) { return(bigpow); } EInteger[] otherPower = ValuePowerOfFiveCache.FindCachedPowerOrSmaller(origdiff); if (otherPower != null) { intcurexp.SubtractBig(otherPower[0]); bigpow = otherPower[1]; mantissa = bigpow; } else { bigpow = EInteger.Zero; } while (intcurexp.Sign > 0) { if (intcurexp.CompareToInt(27) <= 0) { bigpow = FindPowerOfFive(intcurexp.AsInt32()); mantissa *= (EInteger)bigpow; break; } if (intcurexp.CompareToInt(9999999) <= 0) { bigpow = FindPowerOfFive(1).Pow(intcurexp.AsInt32()); mantissa *= (EInteger)bigpow; break; } if (bigpow.IsZero) { bigpow = FindPowerOfFive(1).Pow(9999999); } mantissa *= bigpow; intcurexp.AddInt(-9999999); } ValuePowerOfFiveCache.AddPower(origdiff, mantissa); return(mantissa); }
internal static EInteger FindPowerOfFiveFromBig(EInteger diff) { int sign = diff.Sign; if (sign < 0) { return(EInteger.Zero); } if (sign == 0) { return(EInteger.One); } FastInteger intcurexp = FastInteger.FromBig(diff); if (intcurexp.CompareToInt(54) <= 0) { return(FindPowerOfFive(intcurexp.AsInt32())); } // DebugUtility.Log("Getting power of five from big "+diff); EInteger mantissa = EInteger.One; EInteger bigpow; EInteger origdiff = diff; bigpow = ValuePowerOfFiveCache.GetCachedPower(origdiff); if (bigpow != null) { return(bigpow); } EInteger[] otherPower = ValuePowerOfFiveCache.FindCachedPowerOrSmaller(origdiff); if (otherPower != null) { // DebugUtility.Log("Found cached power " +otherPower[0]+", " // +otherPower[1]); intcurexp.SubtractBig(otherPower[0]); bigpow = otherPower[1]; mantissa = bigpow; } else { bigpow = EInteger.Zero; } while (intcurexp.Sign > 0) { if (intcurexp.CompareToInt(27) <= 0) { bigpow = FindPowerOfFive(intcurexp.AsInt32()); mantissa *= (EInteger)bigpow; break; } if (intcurexp.CompareToInt(9999999) <= 0) { int icurexp = intcurexp.AsInt32(); int halficurexp = icurexp / 2; bigpow = FindPowerOfFive(halficurexp); bigpow = bigpow.Multiply( FindPowerOfFive(icurexp - halficurexp)); mantissa *= (EInteger)bigpow; break; } if (bigpow.IsZero) { bigpow = FindPowerOfFive(1).Pow(9999999); } mantissa *= bigpow; intcurexp.AddInt(-9999999); } ValuePowerOfFiveCache.AddPower(origdiff, mantissa); return(mantissa); }