public static EcmaValue Pow(EcmaValue x, EcmaValue y) { if ((x == 1 || x == -1) && (y == EcmaValue.Infinity || y == EcmaValue.NegativeInfinity)) { return(EcmaValue.NaN); } return(Math.Pow(x.ToDouble(), y.ToDouble())); }
public static EcmaValue Log10(EcmaValue value) { if (value.Type != EcmaValueType.Number) { value = value.ToNumber(); } return(Math.Log10(value.ToDouble())); }
public void SetFloat64(long index, EcmaValue value, DataViewEndianness isLittleEndian) { Guard.BufferNotDetached(this); double doubleValue = value.ToDouble(); ThrowIfOutOfBound(index, sizeof(double)); this.Buffer.SetValue(index + ByteOffset, CheckAndSwap(doubleValue, isLittleEndian)); }
public static EcmaValue Tanh(EcmaValue value) { double x = value.ToDouble(); if (Double.IsInfinity(x)) { return(x > 0 ? 1 : -1); } return(x == 0 ? x : (Math.Exp(x) - Math.Exp(-x)) / (Math.Exp(x) + Math.Exp(-x))); }
public static EcmaValue Trunc(EcmaValue value) { if (value.Type != EcmaValueType.Number) { value = value.ToNumber(); } if (EcmaValue.GetNumberCoercion(value) != EcmaNumberType.Double) { return(value); } return(Math.Truncate(value.ToDouble())); }
public static EcmaValue Expm1(EcmaValue value) { double x = value.ToDouble(); if (x == 0) { return(x); } if (Math.Abs(x) < 1e-5) { return(x + 0.5 * x * x); } return(Math.Exp(x) - 1d); }
public static EcmaValue Log1p(EcmaValue value) { double x = value.ToDouble(); if (x < -1) { return(EcmaValue.NaN); } if (Math.Abs(x) > 1e-4) { return(Math.Log(1 + x)); } return((-0.5 * x + 1.0) * x); }
public static int Compare(EcmaValue x, EcmaValue y) { if (x.Type != EcmaValueType.BigInt) { return(-Compare(y, x)); } BigInteger bigInt = ToBigInteger(x); if (EcmaValue.GetNumberCoercion(y) == EcmaNumberType.Double) { return(((double)bigInt).CompareTo(y.ToDouble())); } return(bigInt.CompareTo(y.ToInt64())); }
public static EcmaValue Sign(EcmaValue value) { switch (EcmaValue.GetNumberCoercion(value)) { case EcmaNumberType.Int64: return(Math.Sign(value.ToInt64())); case EcmaNumberType.Int32: return(Math.Sign(value.ToInt32())); } double x = value.ToDouble(); return(Double.IsNaN(x) ? EcmaValue.NaN : x == 0 ? x : Math.Sign(x)); }
public static EcmaValue Abs(EcmaValue value) { switch (EcmaValue.GetNumberCoercion(value)) { case EcmaNumberType.Double: return(Math.Abs(value.ToDouble())); case EcmaNumberType.Int64: return(Math.Abs(value.ToInt64())); case EcmaNumberType.Int32: return(Math.Abs(value.ToInt32())); } return(Abs(value.ToNumber())); }
public static EcmaValue Ceil(EcmaValue value) { if (value.Type != EcmaValueType.Number) { value = value.ToNumber(); } if (EcmaValue.GetNumberCoercion(value) != EcmaNumberType.Double) { return(value); } double x = value.ToDouble(); double c = Math.Ceiling(x); return(c == 0 && x < 0 ? -0d : c); }
public static EcmaValue Round(EcmaValue value) { if (value.Type != EcmaValueType.Number) { value = value.ToNumber(); } if (EcmaValue.GetNumberCoercion(value) != EcmaNumberType.Double) { return(value); } double x = value.ToDouble(); if (x == 0) { return(x); } double r = Math.Floor(x + 0.5); return(r == 0 && x < 0 ? -0d : r); }
public static EcmaValue Atanh(EcmaValue value) { double x = value.ToDouble(); return(x == 0 ? x : Math.Log((1 + x) / (1 - x)) / 2); }
public static EcmaValue Atan(EcmaValue value) { return(Math.Atan(value.ToDouble())); }
public static EcmaValue Asinh(EcmaValue value) { double x = value.ToDouble(); return(Double.IsInfinity(x) || x == 0 ? x : Math.Log(x + Math.Sqrt(x * x + 1))); }
public static EcmaValue Acosh(EcmaValue value) { double x = value.ToDouble(); return(Math.Log(x + Math.Sqrt(x * x - 1))); }
public static EcmaValue Acos(EcmaValue value) { return(Math.Acos(value.ToDouble())); }
public static EcmaValue Cbrt(EcmaValue value) { double x = value.ToDouble(); return(Double.IsInfinity(x) || x == 0 ? x : Math.Pow(value.ToDouble(), 1f / 3)); }
public static EcmaValue Fround(EcmaValue value) { return((float)value.ToDouble()); }
public static EcmaValue Sqrt(EcmaValue value) { return(Math.Sqrt(value.ToDouble())); }
public static EcmaValue Sinh(EcmaValue value) { double x = value.ToDouble(); return(x == 0 ? x : (Math.Exp(x) - Math.Exp(-x)) / 2); }
public static EcmaValue Exp(EcmaValue value) { return(Math.Exp(value.ToDouble())); }
public static EcmaValue Atan2(EcmaValue y, EcmaValue x) { return(Math.Atan2(y.ToDouble(), x.ToDouble())); }
public static EcmaValue Cosh(EcmaValue value) { double x = value.ToDouble(); return((Math.Exp(x) + Math.Exp(-x)) / 2); }
public static EcmaValue Log2(EcmaValue value) { return(Math.Log(value.ToDouble()) / LN2); }