public static EcmaValue ToBigInt(ulong value) { if (value <= Int64.MaxValue) { return(ToBigInt((long)value)); } BigIntBinder binder = new BigIntBinder(value); return(binder.ToValue()); }
public static EcmaValue ToBigInt(BigInteger value) { if (value >= int64min && value <= int64max) { return(ToBigInt((long)value)); } BigIntBinder binder = new BigIntBinder(value); return(binder.ToValue()); }
public static EcmaValue ToBigInt(double value) { if (Double.IsNaN(value) || Double.IsInfinity(value) || Math.Truncate(value) != value) { throw new EcmaRangeErrorException(InternalString.Error.NumberNotConvertibleToBigInt, value); } if (value >= Int64.MinValue && value <= Int64.MaxValue) { return(ToBigInt((long)value)); } BigIntBinder binder = new BigIntBinder(new BigInteger(value)); return(binder.ToValue()); }
public static EcmaValue Multiply64(EcmaValue x, EcmaValue y) { ThrowIfArgumentNotBigInt(x); ThrowIfArgumentNotBigInt(y); long a = x.ToInt64(); long b = y.ToInt64(); try { return(ToBigInt(checked (a * b))); } catch (OverflowException) { BigIntBinder bigInt = new BigIntBinder(new BigInteger(a) * new BigInteger(b)); return(bigInt.ToValue()); } }
public static EcmaValue Subtract64(EcmaValue x, EcmaValue y) { ThrowIfArgumentNotBigInt(x); ThrowIfArgumentNotBigInt(y); long u = x.ToInt64(); long v = y.ToInt64(); try { return(ToBigInt(checked (u - v))); } catch (OverflowException) { BigIntBinder bigInt = new BigIntBinder(new BigInteger(u) - new BigInteger(v)); return(bigInt.ToValue()); } }