当前位置: 首页>>代码示例>>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;未经允许,请勿转载。