functionlib.cs

来自「在LINUX下实现FFT,提供了源代码和编译函数」· CS 代码 · 共 1,032 行 · 第 1/2 页

CS
1,032
字号
		public override string GetFunction()
		{
			return "sinh";
		}
	}

	/// <summary>
	/// CSqrt class: implements the square root function.
	/// </summary>
	public class CSqrt : EqCompiler.CFunction 
	{
		ArrayList m_alValues;
		
		public CSqrt()
		{
		}

		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CSqrt oSqrt = new CSqrt();
			oSqrt.SetValue(alValues);

			return oSqrt;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues , 1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue1 = (EqCompiler.CValue)m_alValues[0];
			return Math.Sqrt(oValue1.GetValue());
		}

		public override string GetFunction()
		{
			return "sqrt";
		}
	}

	/// <summary>
	/// CCos class: returns the cosine of the specified angle
	/// </summary>
	public class CCos : EqCompiler.CFunction 
	{
		
		ArrayList m_alValues;

		public CCos( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CCos oCos = new CCos();
			oCos.SetValue( alValues );

			return oCos;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues,1);
			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Cos(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "cos";
		}
	}



	/// <summary>
	/// CCosh class: returns the hyperbolic cosine of the specified angle
	/// </summary>
	public class CCosh : EqCompiler.CFunction 
	{
		
		ArrayList m_alValues;


		public CCosh( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CCosh oCos = new CCosh();
			oCos.SetValue( alValues );

			return oCos;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues,1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Cosh(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "cosh";
		}
	}


	/// <summary>
	/// CIf class: implements if(condition, then,else) functionality.
	/// </summary>
	public class CIf : EqCompiler.CFunction
	{
		ArrayList m_alValues;

		public CIf()
		{
		}

		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CIf oIf = new CIf();
			oIf.SetValue( alValues );

			return oIf;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues,3);
            										
			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oTest = (EqCompiler.CValue) m_alValues[0];
			EqCompiler.CValue oThen = (EqCompiler.CValue) m_alValues[1];
			EqCompiler.CValue oElse = (EqCompiler.CValue) m_alValues[2];

			if( oTest.GetValue() != 0.0 )
				return oThen.GetValue();
			else
				return oElse.GetValue();

		}

		public override string GetFunction()
		{
			return "if";
		}
	}


	/// <summary>
	/// CMax class: returns the maximum value among provided parameters
	/// </summary>
	public class CMax : EqCompiler.CFunction
	{
		ArrayList m_alValues;

		public CMax()
		{
		}

		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CMax oMax = new CMax();
			oMax.SetValue( alValues );

			return oMax;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues, 2, -1 );  // check for a minimum of two values (no maximum limit)

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			double dValue = oValue.GetValue();

			for( int i = 1; i < m_alValues.Count; i++ )
			{
				oValue = (EqCompiler.CValue) m_alValues[i];

				dValue = Math.Max(dValue, oValue.GetValue() );
			}

			return dValue;
			


		}

		public override string GetFunction()
		{
			return "max";
		}
	}


	/// <summary>
	/// CRound class:  implements a rouding of a number to the nearest whole number.
	/// </summary>
	public class CRound : EqCompiler.CFunction 
	{
		
		ArrayList m_alValues;


		public CRound( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CRound oRound = new CRound();
			oRound.SetValue( alValues );

			return oRound;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues,1);
			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Round(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "round";
		}
	}



	/// <summary>
	/// CSign class: returns a value that indicates the sign of the provide value.
	///	Returns the following possibilties:
	///	value < 0 = -1
	///	value = 0 = 0
	///	value > 0 = 1
	/// </summary>
	public class CSign : EqCompiler.CFunction
	{
		ArrayList m_alValues;

		public CSign()
		{
		}

		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CSign oSign = new CSign();
			oSign.SetValue( alValues );

			return oSign;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues, 1);
			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Sign(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "sign";
		}
	}

	/// <summary>
	/// CMin class:  returns the minimum value among supplied values.
	/// </summary>
	public class CMin : EqCompiler.CFunction
	{
		ArrayList m_alValues;

		public CMin()
		{
		}

		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CMin oMin = new CMin();
			oMin.SetValue( alValues );

			return oMin;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues, 2, -1 );

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			double dValue = oValue.GetValue();

			for( int i = 1; i < m_alValues.Count; i++ )
			{
				oValue = (EqCompiler.CValue) m_alValues[i];

				dValue = Math.Min(dValue, oValue.GetValue() );
			}

			return dValue;
		}

		public override string GetFunction()
		{
			return "min";
		}
	}



	/// <summary>
	/// CTan class: return the tagent of the supplied angle
	/// </summary>
	public class CTan : EqCompiler.CFunction 
	{
		ArrayList m_alValues;

		public CTan( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CTan oTan = new CTan();
			oTan.SetValue( alValues );

			return oTan;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues,1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Tan(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "tan";
		}
	}

	/// <summary>
	/// CLog class: returns the logarithm of a specified number.
	/// </summary>
	public class CLog : EqCompiler.CFunction 
	{
		ArrayList m_alValues;

		public CLog( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CLog oLog = new CLog();
			oLog.SetValue( alValues );

			return oLog;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues,1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Log(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "log";
		}
	}


	/// <summary>
	/// CLog10 class:  Returns the base 10 logarithm of a specified number.
	/// </summary>
	public class CLog10 : EqCompiler.CFunction 
	{
		ArrayList m_alValues;

		public CLog10( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CLog10 oLog10 = new CLog10();
			oLog10.SetValue( alValues );

			return oLog10;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms( alValues, 1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Log10(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "log10";
		}
	}


	/// <summary>
	/// CTanh class: Returns the hyperbolic tangent of the supplied angle.
	/// </summary>
	public class CTanh : EqCompiler.CFunction 
	{
		ArrayList m_alValues;

		public CTanh( )
		{
		}


		public override EqCompiler.CFunction CreateInstance( ArrayList alValues )
		{
			CTanh oTanh = new CTanh();
			oTanh.SetValue( alValues );

			return oTanh;
		}

		public override void SetValue( ArrayList alValues )
		{
			CheckParms(alValues,1);

			m_alValues = alValues;
		}

		public override double GetValue()
		{
			EqCompiler.CValue oValue = (EqCompiler.CValue) m_alValues[0];
			return Math.Tanh(oValue.GetValue());
		}

		public override string GetFunction()
		{
			return "tanh";
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?