예제 #1
0
        protected void ProcessFunction(ref FunctionEvent e)
        {
            if (String.Compare(e.Name, Functions.abs.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Abs((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Abs((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.arcos.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Acos((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Acos((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.arsin.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Asin((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Asin((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.arctan.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Atan((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Atan((DoubleArray)e.Parameters[0]);
                    }
                }
                else if (e.Parameters.Count == 2)
                {
                    if (e.Parameters[0] is Double && e.Parameters[1] is Double)
                    {
                        e.Result = Math.Atan2((double)e.Parameters[0], (double)e.Parameters[1]);
                    }
                    else if (e.Parameters[0] is DoubleArray && e.Parameters[1] is Double)
                    {
                        e.Result = DoubleArray.Atan2((DoubleArray)e.Parameters[0], (double)e.Parameters[1]);
                    }
                    else if (e.Parameters[0] is Double && e.Parameters[1] is DoubleArray)
                    {
                        e.Result = DoubleArray.Atan2((Double)e.Parameters[0], (DoubleArray)e.Parameters[1]);
                    }
                    else
                    {
                        e.Status = FunctionStatus.WrongArgument;
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.ceiling.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Ceiling((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Ceiling((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.cos.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Cos((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Cos((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.cosh.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Cosh((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Cosh((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.exp.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Exp((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Exp((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.floor.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Floor((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Floor((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.log.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Log((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Log((DoubleArray)e.Parameters[0]);
                    }
                }
                else if (e.Parameters.Count == 2)
                {
                    if (e.Parameters[0] is Double && e.Parameters[1] is Double)
                    {
                        e.Result = Math.Log((double)e.Parameters[0], (int)e.Parameters[1]);
                    }
                    else if (e.Parameters[0] is DoubleArray && e.Parameters[1] is Double)
                    {
                        e.Result = DoubleArray.Log((DoubleArray)e.Parameters[0], (int)e.Parameters[1]);
                    }
                    else
                    {
                        e.Status = FunctionStatus.WrongArgument;
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.log10.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Log10((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Log10((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.pow.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 2)
                {
                    if (e.Parameters[0] is Double && e.Parameters[1] is Double)
                    {
                        e.Result = Math.Pow((double)e.Parameters[0], (double)e.Parameters[1]);
                    }
                    else if (e.Parameters[0] is DoubleArray && e.Parameters[1] is Double)
                    {
                        e.Result = DoubleArray.Pow((DoubleArray)e.Parameters[0], (double)e.Parameters[1]);
                    }
                    else
                    {
                        e.Status = FunctionStatus.WrongArgument;
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.round.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Round((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Round((DoubleArray)e.Parameters[0]);
                    }
                }
                else if (e.Parameters.Count == 2)
                {
                    if (e.Parameters[0] is Double && e.Parameters[1] is Double)
                    {
                        e.Result = Math.Round((double)e.Parameters[0], (int)((double)e.Parameters[1]));
                    }
                    else if (e.Parameters[0] is DoubleArray && e.Parameters[1] is Double)
                    {
                        e.Result = DoubleArray.Round((DoubleArray)e.Parameters[0], (int)((double)e.Parameters[1]));
                    }
                    else
                    {
                        e.Status = FunctionStatus.WrongArgument;
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.sin.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Sin((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Sin((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.sinh.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Sinh((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Sinh((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.sqrt.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Sqrt((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Sqrt((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.tan.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Tan((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Tan((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.tanh.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Tanh((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Tanh((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.truncate.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = Math.Truncate((double)e.Parameters[0]);
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.Truncate((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.mean.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.MeanValue((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }

            // Conversion Degree <-> Radian
            else if (String.Compare(e.Name, Functions.toDeg.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = (double)e.Parameters[0] / Math.PI * 180.0;
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.RadianToDegree((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }
            else if (String.Compare(e.Name, Functions.toRad.ToString(), true) == 0)
            {
                if (e.Parameters.Count == 1)
                {
                    if (e.Parameters[0] is Double)
                    {
                        e.Result = (double)e.Parameters[0] * Math.PI / 180.0;
                    }
                    else if (e.Parameters[0] is DoubleArray)
                    {
                        e.Result = DoubleArray.DegreeToRadian((DoubleArray)e.Parameters[0]);
                    }
                }
                else
                {
                    e.Status = FunctionStatus.WrongParameterCount;
                }
            }

            // Unknown function name
            else
            {
                e.Status = FunctionStatus.UndefinedFunction;
            }
        }