在這似乎運作良好,我有以下聲明的程序:爲什麼這些可以聲明爲整數?
#include <stdio.h>
#include "system.h"
signed char input[4]; /* The 4 most recent input values */
char get_q7(void);
void put_q7(char);
void firFixed(signed char input[4]);
const int c0 = (0.0299 * 128 + 0.5); /* Converting from float to Q7 is multiplying by 2^n i.e. 128 = 2^7 since we use Q7 and round to the nearest integer*/
const int c1 = (0.4701 * 128 + 0.5);
const int c2 = (0.4701 * 128 + 0.5);
const int c3 = (0.0299 * 128 + 0.5);
const int half = (0.5000 * 128 + 0.5);
enum { Q7_BITS = 7 };
void firFixed(signed char input[4])
{
int sum = c0*input[0] + c1*input[1] + c2*input[2] + c3*input[3];
signed char output = (signed char)((sum + half) >> Q7_BITS);
put_q7(output);
}
int main(void)
{
int a;
while(1)
{
for (a = 3 ; a > 0 ; a--)
{
input[a] = input[a-1];
}
input[0]=get_q7();
firFixed(input);
}
return 0;
}
但我不明白它是如何possibl申報分數爲int
它與常數來完成。它應該是Q7符號,但爲什麼它是這樣做的,編譯器如何接受一個小數的整數?它是否只需要分數的整數部分,如果是的話,爲什麼不需要投射?