Esempio n. 1
0
        public override void Eval(ref IValue ret, IValue[] a_pArg)
        {
            Global.MUP_VERIFY(a_pArg.Length == 2);

            if (a_pArg[0].IsNonComplexScalar() && a_pArg[1].IsNonComplexScalar())
            {
                if (a_pArg[0].IsInteger() && a_pArg[1].IsInteger())
                {
                    ret = a_pArg[0].AsInteger() * a_pArg[1].AsInteger();
                }
                else
                {
                    ret = a_pArg[0].AsFloat() * a_pArg[1].AsFloat();
                }
            }
            else if (a_pArg[0].IsComplex() && a_pArg[1].IsComplex())
            {
                // multiplication of two imaginary numbers
                ret = Complex.Multiply(a_pArg[0].GetComplex(), a_pArg[1].GetComplex());
            }

            else if (a_pArg[0].IsComplex())
            {
                // multiplication of two imaginary numbers
                ret = Complex.Multiply(a_pArg[0].GetComplex(), a_pArg[1].AsComplex());
            }

            else if (a_pArg[1].IsComplex())
            {
                // multiplication of two imaginary numbers
                ret = Complex.Multiply(a_pArg[0].AsComplex(), a_pArg[1].GetComplex());
            }
            else
            {
                ret = a_pArg[0] * a_pArg[1];
            }

            if (ret.IsComplex())
            {
                const double EPSILON = 1e-16;
                Complex      c       = ret.GetComplex();
                double       re      = c.Real;
                double       im      = c.Imaginary;
                if (Math.Abs(re) < EPSILON)
                {
                    re = 0;
                }
                if (Math.Abs(im) < EPSILON)
                {
                    im = 0;
                }
                ret = new Complex(re, im);
            }
        }
Esempio n. 2
0
 public override Complex GetComplex(bool assert = true)
 {
     try
     {
         return(m_pVal.GetComplex(assert));
     }
     catch (ParserError exc)
     {
         exc.GetContext().Ident = GetIdent();
         throw;
     }
 }
Esempio n. 3
0
        public override void Eval(ref IValue ret, IValue[] arg)
        {
            Global.MUP_VERIFY(arg.Length == 2);

            if (arg[0].IsComplex() && arg[1].IsComplex())
            {
                ret = Complex.Pow(arg[0].GetComplex(), arg[1].GetComplex());;
            }

            else if (arg[0].IsComplex())
            {
                // Exponentation of two complex numbers
                ret = Complex.Pow(arg[0].GetComplex(), arg[1].AsComplex());
            }

            else if (arg[1].IsComplex())
            {
                // Exponentation of two complex numbers
                ret = Complex.Pow(arg[0].AsComplex(), arg[1].GetComplex());
            }
            else if (arg[0].IsInteger() && arg[1].IsInteger())
            {
                if (arg[0].AsInteger() < 0)
                {
                    ret = Complex.Pow(arg[0].AsComplex(), arg[1].AsComplex());
                }
                else
                {
                    ret = (long)Math.Pow(arg[0].GetInteger(), arg[1].GetInteger());
                }
            }
            else
            {
                if (arg[0].AsFloat() < 0)
                {
                    ret = Complex.Pow(arg[0].AsComplex(), arg[1].AsComplex());
                }
                else
                {
                    ret = Math.Pow(arg[0].AsFloat(), arg[1].AsFloat());
                }
            }

            if (ret.IsComplex())
            {
                const double EPSILON = 1e-14;
                Complex      c       = ret.GetComplex();
                double       re      = c.Real;
                double       im      = c.Imaginary;

                if (Math.Abs(re) < EPSILON)
                {
                    re = 0;
                }
                if (Math.Abs(im) < EPSILON)
                {
                    im = 0;
                }
                ret = new Complex(re, im);
            }
        }