Exemple #1
0
 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()));
 }
Exemple #2
0
 public static EcmaValue Log10(EcmaValue value)
 {
     if (value.Type != EcmaValueType.Number)
     {
         value = value.ToNumber();
     }
     return(Math.Log10(value.ToDouble()));
 }
Exemple #3
0
        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));
        }
Exemple #4
0
        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)));
        }
Exemple #5
0
 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()));
 }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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()));
        }
Exemple #9
0
        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));
        }
Exemple #10
0
        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()));
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        public static EcmaValue Atanh(EcmaValue value)
        {
            double x = value.ToDouble();

            return(x == 0 ? x : Math.Log((1 + x) / (1 - x)) / 2);
        }
Exemple #14
0
 public static EcmaValue Atan(EcmaValue value)
 {
     return(Math.Atan(value.ToDouble()));
 }
Exemple #15
0
        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)));
        }
Exemple #16
0
        public static EcmaValue Acosh(EcmaValue value)
        {
            double x = value.ToDouble();

            return(Math.Log(x + Math.Sqrt(x * x - 1)));
        }
Exemple #17
0
 public static EcmaValue Acos(EcmaValue value)
 {
     return(Math.Acos(value.ToDouble()));
 }
Exemple #18
0
        public static EcmaValue Cbrt(EcmaValue value)
        {
            double x = value.ToDouble();

            return(Double.IsInfinity(x) || x == 0 ? x : Math.Pow(value.ToDouble(), 1f / 3));
        }
Exemple #19
0
 public static EcmaValue Fround(EcmaValue value)
 {
     return((float)value.ToDouble());
 }
Exemple #20
0
 public static EcmaValue Sqrt(EcmaValue value)
 {
     return(Math.Sqrt(value.ToDouble()));
 }
Exemple #21
0
        public static EcmaValue Sinh(EcmaValue value)
        {
            double x = value.ToDouble();

            return(x == 0 ? x : (Math.Exp(x) - Math.Exp(-x)) / 2);
        }
Exemple #22
0
 public static EcmaValue Exp(EcmaValue value)
 {
     return(Math.Exp(value.ToDouble()));
 }
Exemple #23
0
 public static EcmaValue Atan2(EcmaValue y, EcmaValue x)
 {
     return(Math.Atan2(y.ToDouble(), x.ToDouble()));
 }
Exemple #24
0
        public static EcmaValue Cosh(EcmaValue value)
        {
            double x = value.ToDouble();

            return((Math.Exp(x) + Math.Exp(-x)) / 2);
        }
Exemple #25
0
 public static EcmaValue Log2(EcmaValue value)
 {
     return(Math.Log(value.ToDouble()) / LN2);
 }