我对C语言很陌生。我想问一下如何实现C函数乘以两个8位有符号不动点数。函数还应检查有符号x符号乘的角大小写。将乘法结果截断为8位.当我使用带角点的乘法函数时,它会产生以下错误
错误C2224:'.real‘的左侧必须具有结构/联合类型IntelliSense:表达式必须具有类类型 错误C2224:“.imag”的左侧必须具有结构/联合类型
因为我是C语言的新手,所以我不能准确地理解错误信息。这是我想要写的代码。无法解决:
typedef struct COMPLEX
{
short real;
short imag;
}COMPLEX;
COMPLEX ComplexMultFixed(COMPLEX z1, COMPLEX z2);
char multiplied(char z1, char z2)
{
short c;
int i,j;
short L1,L2;
char ans;
COMPLEX out;
int overflow;
c = z1 * z2;
if (c != 0x4000)
{
c *=2;
}
else
{
overflow = 1;
c = 0x7fff;
}
L1 = z1.real * z2.real;
L2 = z1.imag * z2.imag; // Rounding and truncation
out.real = (((L1 - L2)+0x0040)>>7);
L1 = z1.real * z2.imag;
L2 = z1.imag * z2.real;
// Rounding and truncation
out.imag = (((L1 + L2)+0x0040)>>7);
return(ans);
}发布于 2014-03-23 10:24:25
以下两个函数似乎有些混乱。
COMPLEX ComplexMultFixed(COMPLEX z1, COMPLEX z2);
char multiplied(char z1, char z2)
{对你来说也一样吗?对我来说应该是一样的。
将类型从char更改为COMPLEX
COMPLEX multiplied(COMPLEX z1, COMPLEX z2) https://stackoverflow.com/questions/22589239
复制相似问题