我有這段代碼運行一個循環。小寫x
變量始終打印正確。大寫X
var有時正確打印,有時打印nan
或junk
。爲什麼?什麼導致nan錯誤結果?
N.B.數據總是相同的。
Link to my other SO question which shows how this is being used.200點賞金!
double (*x)[2];
double (*X)[2];
x = malloc(2 * 512 * sizeof(double));
X = malloc(2 * 512 * sizeof(double));
for (j = 0; j < 10; j++){
(*x)[j] = // values inserted from method argument.;
}
fft(512, x, X);
for (j = 0; j < 512; j++){
if (i==512*20) {
NSLog(@"PRE POST %f - %f",(*x)[j], (*X)[j]);
}
}
free(x);
free(X);
這看起來不像C/Objective-C特定的問題。也許FFT沒有在您試圖計算的整個頻譜上定義。或者它被定義但切向爲0.0或無限。 –