當前位置: 首頁>>代碼示例>>C#>>正文


C# Math.BigInteger類代碼示例

本文整理匯總了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;
 }
開發者ID:nieve,項目名稱:ironruby,代碼行數:15,代碼來源:Protocols.cs

示例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;
 }
開發者ID:jxnmaomao,項目名稱:ironruby,代碼行數:11,代碼來源:DecimalOps.cs

示例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;
     }
 }
開發者ID:netcharm,項目名稱:ironclad,代碼行數:19,代碼來源:PythonMapper_numbers.cs

示例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())
            );
        }
開發者ID:bclubb,項目名稱:ironruby,代碼行數:23,代碼來源:ConstantExpression.cs

示例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;
 }
開發者ID:mscottford,項目名稱:ironruby,代碼行數:10,代碼來源:StringFormatter.cs

示例6: Subtract

 public static BigInteger Subtract(int self, BigInteger other) {
     return (BigInteger)self - other;
 }
開發者ID:tnachen,項目名稱:ironruby,代碼行數:3,代碼來源:FixnumOps.cs

示例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;
 }
開發者ID:joshholmes,項目名稱:ironruby,代碼行數:19,代碼來源:BigNumOps.cs

示例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;
 }
開發者ID:nieve,項目名稱:ironruby,代碼行數:8,代碼來源:Protocols.cs

示例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;
        }
開發者ID:mscottford,項目名稱:ironruby,代碼行數:9,代碼來源:MutableStringOps.cs

示例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;
        }
開發者ID:jschementi,項目名稱:iron,代碼行數:11,代碼來源:MathUtils.cs

示例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'");
     }
 }
開發者ID:ExpertsInside,項目名稱:IronSP,代碼行數:20,代碼來源:BasicSocket.cs

示例12: from_address

 public _Array from_address(CodeContext/*!*/ context, BigInteger ptr) {
     _Array res = (_Array)CreateInstance(context);
     res.SetAddress(new IntPtr(ptr.ToInt64()));
     return res;
 }
開發者ID:techarch,項目名稱:ironruby,代碼行數:5,代碼來源:ArrayType.cs

示例13: SetBigInteger

 internal void SetBigInteger(BigInteger value) {
     BigInteger = value;
     _type = TokenValueType.BigInteger;
 }
開發者ID:mscottford,項目名稱:ironruby,代碼行數:4,代碼來源:TokenValue.cs

示例14: from_address

 public _Structure from_address(CodeContext/*!*/ context, BigInteger address) {
     return from_address(context, new IntPtr(address.ToInt64()));
 }
開發者ID:joshholmes,項目名稱:ironruby,代碼行數:3,代碼來源:StructType.cs

示例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);
        }
開發者ID:atczyc,項目名稱:ironruby,代碼行數:14,代碼來源:_winreg.cs


注:本文中的Microsoft.Scripting.Math.BigInteger類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。