本文整理汇总了C#中Microsoft.Scripting.Math.BigInteger类的典型用法代码示例。如果您正苦于以下问题:C# BigInteger类的具体用法?C# BigInteger怎么用?C# BigInteger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BigInteger类属于Microsoft.Scripting.Math命名空间,在下文中一共展示了BigInteger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Add
public static object Add(BinaryOpStorage/*!*/ coercionStorage, BinaryOpStorage/*!*/ binaryOpSite,
RubyContext/*!*/ context, BigInteger/*!*/ self, object other) {
return Protocols.CoerceAndApply(coercionStorage, binaryOpSite, "+", context, self, other);
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:4,代码来源:BigNumOps.cs
示例17: CastToUnsignedBigInteger
private BigInteger/*!*/ CastToUnsignedBigInteger(BigInteger/*!*/ value) {
return MakeBigIntegerFromByteArray(value.ToByteArray());
}
开发者ID:mscottford,项目名称:ironruby,代码行数:3,代码来源:StringFormatter.cs
示例18: GenerateMask
private BigInteger/*!*/ GenerateMask(BigInteger/*!*/ value) {
byte[] bytes = new byte[value.ToByteArray().Length];
for (int i = 0; i < bytes.Length; i++) {
bytes[i] = 0xFF;
}
return MakeBigIntegerFromByteArray(bytes);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:7,代码来源:StringFormatter.cs
示例19: ioctl
public int ioctl(BigInteger cmd, int option) {
return _socket.IOControl((IOControlCode)cmd.ToInt64(), BitConverter.GetBytes(option), null);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:3,代码来源:socket.cs
示例20: BitLength
// Like GetBitCount(Abs(x)), except 0 maps to 0
public static int BitLength(BigInteger x) {
if (x.IsZero()) {
return 0;
}
return x.Abs().GetBitCount();
}
开发者ID:jschementi,项目名称:iron,代码行数:8,代码来源:MathUtils.cs
注:本文中的Microsoft.Scripting.Math.BigInteger类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论