|
发表于 2023-5-30 14:56:21
|
显示全部楼层
Keil中支持复数的运算,其实就是定义了几个复数运算的函数。就像这个样子的:
//-----------------------------------------------------------------------------
// Div_Complex
//-----------------------------------------------------------------------------
//
// Return Value : true if no error in a floating-point number operation
// Parameters : A, B and pointer on C (real and imaginary parts)
//
// C = A / B
// If an error is detected the operation is not performed.
// Usage: float Rsm,Xsm;
// Div_Complex(Vp, Vq, Ip, Iq, &Rsm, &Xsm); // measured values: Zxm = (Vp+jVq)/(Ip+jIq) = Rsm + jXsm
//
void Div_Complex(float A_Real, float A_Imag, float B_Real, float B_Imag, float *C_Real, float *C_Imag)
{
// u8 a, b;
float CR, CI;
float Y = B_Real * B_Real + B_Imag * B_Imag;
if (fabs(Y) < MINFLOAT)
Y = MINFLOAT;
CR = (A_Real * B_Real + A_Imag * B_Imag) / Y;
CI = (A_Imag * B_Real - A_Real * B_Imag) / Y;
// a = chkfloat(CR); // >= 2 if there is an error
// b = chkfloat(CI);
// if (a >= 2 || b >= 2)
// return false;
*C_Real = CR;
*C_Imag = CI;
// return true;
} // Div_Complex
//-----------------------------------------------------------------------------
// Mul_Complex
//-----------------------------------------------------------------------------
//
// Return Value : true if no error in a floating-point number operation
// Parameters : A, B and pointer on C (real and imaginary parts)
//
// C = A * B
// If an error is detected the operation is not performed.
//
void Mul_Complex(float A_Real, float A_Imag, float B_Real, float B_Imag, float *C_Real, float *C_Imag)
{
// u8 a, b;
float CR, CI;
CR = (A_Real * B_Real - A_Imag * B_Imag);
CI = (A_Imag * B_Real + A_Real * B_Imag);
// a = chkfloat(CR); // >= 2 if there is an error
// b = chkfloat(CI);
// if (a >= 2 || b >= 2)
// return false;
*C_Real = CR;
*C_Imag = CI;
// return true;
} // Mul_Complex
|
|