internal static UInt64 ToUInt64(BigInteger value) { UInt64 result; if (value.AsUInt64(out result)) { return result; } throw RubyExceptions.CreateRangeError("number too big to convert into System::UInt64"); }
public static int __hash__(BigInteger self) { #if CLR4 // TODO: we might need our own hash code implementation. This avoids assertion failure. if (self == -2147483648) { return -2147483648; } #endif // check if it's in the Int64 or UInt64 range, and use the built-in hashcode for that instead // this ensures that objects added to dictionaries as (U)Int64 can be looked up with Python longs Int64 i64; if (self.AsInt64(out i64)) { return Int64Ops.__hash__(i64); } else { UInt64 u64; if (self.AsUInt64(out u64)) { return UInt64Ops.__hash__(u64); } } // Call the DLR's BigInteger hash function, which will return an int32 representation of // b if b is within the int32 range. We use that as an optimization for hashing, and // assert the assumption below. int hash = self.GetHashCode(); #if DEBUG int i; if (self.AsInt32(out i)) { Debug.Assert(i == hash, String.Format("hash({0}) == {1}", i, hash)); } #endif return hash; }
public static bool AsUInt64(BigInteger self, out ulong res) { return self.AsUInt64(out res); }
internal static string/*!*/ ConvertToHostString(BigInteger/*!*/ address) { Assert.NotNull(address); ulong u; if (address.AsUInt64(out u)) { if (u <= UInt32.MaxValue) { // IPv4: return ConvertToHostString((uint)u); } else { // IPv6: byte[] bytes = new byte[8]; for (int i = bytes.Length - 1; i >= 0; --i) { bytes[i] = (byte)(u & 0xff); u >>= 8; } return new IPAddress(bytes).ToString(); } } else { throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad long'"); } }