public BigInt remainder(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { return BigInt.valueOf(_lpart % y._lpart); } return BigInt.fromBigInteger(this.toBigInteger().Mod(y.toBigInteger())); }
public static object ReduceBigInt(BigInt val) { if (val.Bipart == null) return num(val.Lpart); return val.Bipart; }
public BigInt multiply(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { long ret = _lpart * y._lpart; if (y._lpart == 0 || (_lpart != Int64.MinValue && unchecked(ret / y._lpart) == _lpart )) return BigInt.valueOf(ret); } return BigInt.fromBigInteger(this.toBigInteger().Multiply(y.toBigInteger())); }
public BigInt quotient(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { return BigInt.valueOf(_lpart / y._lpart); } return BigInt.fromBigInteger(this.toBigInteger().Divide(y.toBigInteger())); }
public bool lt(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { return _lpart < y._lpart; } return this.toBigInteger().CompareTo(y.toBigInteger()) < 0; }
public BigInt add(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { long ret = _lpart + y._lpart; if ((ret ^ _lpart) >= 0 || (ret ^ y._lpart) >= 0) return BigInt.valueOf(ret); } return BigInt.fromBigInteger(this.toBigInteger().Add(y.toBigInteger())); }
public BigInt multiply(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { long ret = _lpart * y._lpart; if (y._lpart == 0 || ret / y._lpart == _lpart) return BigInt.valueOf(ret); } return BigInt.fromBigInteger(this.toBigInteger().Multiply(y.toBigInteger())); }
public BigInt quotient(BigInt y) { if ((_bipart == null) && (y._bipart == null)) { if (_lpart == Int64.MinValue && y._lpart == -1) return BigInt.fromBigInteger(this.toBigInteger().Negate()); return BigInt.valueOf(_lpart / y._lpart); } return BigInt.fromBigInteger(this.toBigInteger().Divide(y.toBigInteger())); }
public static object MatchNumber(string s) { Match m = intRE.Match(s); if (m.Success) { if (m.Groups[2].Success) { // matched 0 or 0N only if (m.Groups[8].Success) { return(BigInt.ZERO); } return(0L); } bool isNeg = m.Groups[1].Value == "-"; string n = null; int radix = 10; if (m.Groups[3].Success) { n = m.Groups[3].Value; radix = 10; } else if (m.Groups[4].Success) { n = m.Groups[4].Value; radix = 16; } else if (m.Groups[5].Success) { n = m.Groups[5].Value; radix = 8; } else if (m.Groups[7].Success) { n = m.Groups[7].Value; radix = Int32.Parse(m.Groups[6].Value, System.Globalization.CultureInfo.InvariantCulture); } if (n == null) { return(null); } BigInteger bn = BigInteger.Parse(n, radix); if (isNeg) { bn = bn.Negate(); } if (m.Groups[8].Success) // N suffix { return(BigInt.fromBigInteger(bn)); } long ln; if (bn.AsInt64(out ln)) { return(Numbers.num(ln)); } return(BigInt.fromBigInteger(bn)); } m = floatRE.Match(s); if (m.Success) { if (m.Groups[4].Success) { string val = m.Groups[1].Value; // MS implementation of java.util.BigDecimal has a bug when the string has a leading+ //if ( val[0] == '+' ) // val = val.Substring(1); return(BigDecimal.Parse(val)); } return((object)Double.Parse(s, System.Globalization.CultureInfo.InvariantCulture)); } m = ratioRE.Match(s); if (m.Success) { // There is a bug in the BigInteger c-tor that causes it barf on a leading +. string numerString = m.Groups[1].Value; string denomString = m.Groups[2].Value; if (numerString[0] == '+') { numerString = numerString.Substring(1); } //return Numbers.BIDivide(new BigInteger(numerString), new BigInteger(denomString)); return(Numbers.divide( Numbers.ReduceBigInt(BigInt.fromBigInteger(BigInteger.Parse(numerString))), Numbers.ReduceBigInt(BigInt.fromBigInteger(BigInteger.Parse(denomString))))); } return(null); }