Microsoft.Scripting.Math.BigInteger.AsInt64 C# (CSharp) Méthode

AsInt64() public méthode

public AsInt64 ( long &ret ) : bool
ret long
Résultat bool
    public bool AsInt64(out long ret) {
      ret = 0;
      if (sign == 0) return true;
      if (Length > 2) return false;
      if (data.Length == 1) {
        ret = sign * (long)data[0];
        return true;
      }
      ulong tmp = (((ulong)data[1]) << 32 | (ulong)data[0]);
      if (tmp > 0x8000000000000000) return false;
      if (tmp == 0x8000000000000000 && sign == 1) return false;
      ret = ((long)tmp) * sign;
      return true;
    }

Usage Example

        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())
            );
        }
All Usage Examples Of Microsoft.Scripting.Math.BigInteger::AsInt64