本文整理汇总了C#中Microsoft.Scripting.Math.BigInteger类的典型用法代码示例。如果您正苦于以下问题:C# BigInteger类的具体用法?C# BigInteger怎么用?C# BigInteger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BigInteger类属于Microsoft.Scripting.Math命名空间,在下文中一共展示了BigInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Normalize
/// <summary>
/// Converts a BigInteger to int if it is small enough
/// </summary>
/// <param name="x">The value to convert</param>
/// <returns>An int if x is small enough, otherwise x.</returns>
/// <remarks>
/// Use this helper to downgrade BigIntegers as necessary.
/// </remarks>
public static object/*!*/ Normalize(BigInteger/*!*/ x) {
int result;
if (x.AsInt32(out result)) {
return ScriptingRuntimeHelpers.Int32ToObject(result);
}
return x;
}
示例2: __cmp__
internal static int __cmp__(decimal x, BigInteger y) {
if (object.ReferenceEquals(y, null)) return +1;
BigInteger bx = BigInteger.Create(x);
if (bx == y) {
decimal mod = x % 1;
if (mod == 0) return 0;
if (mod > 0) return +1;
else return -1;
}
return bx > y ? +1 : -1;
}
示例3: PyInt_AsUnsignedLongMask
PyInt_AsUnsignedLongMask(IntPtr valuePtr)
{
try
{
BigInteger unmasked = NumberMaker.MakeBigInteger(this.scratchContext, this.Retrieve(valuePtr));
BigInteger mask = new BigInteger(UInt32.MaxValue) + 1;
BigInteger masked = BigInteger.Mod(unmasked, mask);
if (masked < 0)
{
masked += mask;
}
return masked.ToUInt32();
}
catch (Exception e)
{
this.LastException = e;
return 0xFFFFFFFF;
}
}
示例4: BigIntegerConstant
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())
);
}
示例5: AppendBaseBigInteger
private StringBuilder/*!*/ AppendBaseBigInteger(BigInteger/*!*/ value, int radix) {
StringBuilder/*!*/ str = new StringBuilder();
if (value == 0) str.Append('0');
while (value != 0) {
int digit = (value % radix).ToInt32();
str.Append(_LowerDigits[digit]);
value /= radix;
}
return str;
}
示例6: Subtract
public static BigInteger Subtract(int self, BigInteger other) {
return (BigInteger)self - other;
}
示例7: ShiftOverflowCheck
/// <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;
}
示例8: ConvertToDouble
public static double ConvertToDouble(RubyContext/*!*/ context, BigInteger/*!*/ bignum) {
double result;
if (bignum.TryToFloat64(out result)) {
return result;
}
context.ReportWarning("Bignum out of Float range");
return bignum.Sign > 0 ? Double.PositiveInfinity : Double.NegativeInfinity;
}
示例9: GetBigChecksum
private static BigInteger GetBigChecksum(MutableString/*!*/ self, int start, BigInteger/*!*/ sum, int bitCount) {
BigInteger mask = (((BigInteger)1) << bitCount) - 1;
int length = self.GetByteCount();
for (int i = start; i < length; i++) {
sum = (sum + self.GetByte(i)) & mask;
}
return sum;
}
示例10: Random
public static BigInteger Random(this Random generator, BigInteger limit) {
ContractUtils.Requires(limit.Sign > 0, "limit");
ContractUtils.RequiresNotNull(generator, "generator");
// TODO: this doesn't yield a uniform distribution (small numbers will be picked more frequently):
uint[] result = new uint[limit.GetWordCount() + 1];
for (int i = 0; i < result.Length; i++) {
result[i] = unchecked((uint)generator.Next());
}
return new BigInteger(1, result) % limit;
}
示例11: ConvertToHostString
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'");
}
}
示例12: from_address
public _Array from_address(CodeContext/*!*/ context, BigInteger ptr) {
_Array res = (_Array)CreateInstance(context);
res.SetAddress(new IntPtr(ptr.ToInt64()));
return res;
}
示例13: SetBigInteger
internal void SetBigInteger(BigInteger value) {
BigInteger = value;
_type = TokenValueType.BigInteger;
}
示例14: from_address
public _Structure from_address(CodeContext/*!*/ context, BigInteger address) {
return from_address(context, new IntPtr(address.ToInt64()));
}
示例15: ConnectRegistry
public static HKEYType ConnectRegistry(string computerName, BigInteger key) {
if (string.IsNullOrEmpty(computerName))
computerName = string.Empty;
RegistryKey newKey;
try {
newKey = RegistryKey.OpenRemoteBaseKey(MapSystemKey(key), computerName);
}catch(IOException ioe) {
throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_BAD_NETPATH, ioe.Message);
} catch (Exception e) {
throw new ExternalException(e.Message);
}
return new HKEYType(newKey);
}