private static Expression BigIntegerConstant(BigInteger value) { int ival; if (value.AsInt32(out ival)) { return Expression.Call( typeof(BigInteger).GetMethod("Create", new Type[] { typeof(int) }), Expression.Constant(ival) ); } long lval; if (value.AsInt64(out lval)) { return Expression.Call( typeof(BigInteger).GetMethod("Create", new Type[] { typeof(long) }), Expression.Constant(lval) ); } return Expression.New( typeof(BigInteger).GetConstructor(new Type[] { typeof(int), typeof(uint[]) }), Expression.Constant((int)value.Sign), CreateUIntArray(value.GetBits()) ); }
public static int Size(BigInteger/*!*/ self) { //TODO: Should we expose the number of bytes per word in a BitInteger? return self.GetBits().Length * 4; }
private void WriteBignumValue(BigInteger/*!*/ value) { char sign; if (value.Sign > 0) { sign = '+'; } else if (value.Sign < 0) { sign = '-'; } else { sign = '0'; } _writer.Write((byte)sign); uint[] bits = value.GetBits(); int n = bits.Length * 2, mn = bits.Length - 1; bool truncate = false; if (bits.Length > 0 && (bits[mn] >> 16) == 0) { n--; truncate = true; } WriteInt32(n); for (int i = 0; i < bits.Length; i++) { if (truncate && i == mn) { _writer.Write(unchecked((ushort)(bits[i]))); } else { _writer.Write(bits[i]); } } }