private static string ToBinary(BigInteger val, bool includeType, bool lowercase) { Debug.Assert(!val.IsNegative()); string digits; digits = ToDigits(val, 2, lowercase); if (includeType) { digits = (lowercase ? "0b" : "0B") + digits; } return digits; }
internal static string ToBinary(BigInteger val) { string res = ToBinary(val.Abs(), true, true); if (val.IsNegative()) { res = "-" + res; } return res; }
/// <summary> /// Test for shift overflow on negative BigIntegers /// </summary> /// <param name="self">Value before shifting</param> /// <param name="result">Value after shifting</param> /// <returns>-1 if we overflowed, otherwise result</returns> /// <remarks> /// Negative Bignums are supposed to look like they are stored in 2s complement infinite bit string, /// a negative number should always have spare 1s available for on the left hand side for right shifting. /// E.g. 8 == ...0001000; -8 == ...1110111, where the ... means that the left hand value is repeated indefinitely. /// The test here checks whether we have overflowed into the infinite 1s. /// [Arguably this should get factored into the BigInteger class.] /// </remarks> private static BigInteger/*!*/ ShiftOverflowCheck(BigInteger/*!*/ self, BigInteger/*!*/ result) { if (self.IsNegative() && result.IsZero()) { return -1; } return result; }
public static object/*!*/ RightShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { if (self.IsNegative()) { return -1; } return 0; }
public static double ConvertBignumToFloat(BigInteger/*!*/ value) { double result; return value.TryToFloat64(out result) ? result : (value.IsNegative() ? Double.NegativeInfinity : Double.PositiveInfinity); }
public static object RightShift(BigInteger/*!*/ self, [NotNull]BigInteger/*!*/ other) { return self.IsNegative() ? ClrInteger.MinusOne : ClrInteger.Zero; }