什么原因导致南错误结果? [英] What causes a nan error result?
问题描述
我有这个块code的它通过循环运行。小写 X
VAR总是打印正确。上壳 X
VAR有时打印正确,有时打印男
或垃圾
。为什么呢?
N.B。数据始终是相同的。
链接到我的其他太问题,显示了这是如何被使用。 < STRONG>赏金200分!
双(* X)[2];
双(* X)[2];X =的malloc(2 * 512 * sizeof的(双));
X =的malloc(2 * 512 * sizeof的(双));为(J = 0; J&小于10; J ++){
(* X)[J]从方法参数插入= //值;
}FFT(512中,x,X);为(J = 0; J&所述; 512; J ++){
如果(我== 512 * 20){
的NSLog(@pre POST%F - %F,(* X)[J],(* X)[J]);
}
}
免费(X);
免费(X);
我试图运行这一点 - 使用初始化数据(* X)[J] = j的
并取消在我== 512 * 20
印刷条件。所有值回来了罚款。我也试图与随机输入数据 - 还是不错的。什么是你的输入数据的性质是什么?
(我会看你的其他问题以及)
编辑:我要指出我填写X数组的512个值 - 你的循环只以上的10罢了,这么多的输入数组是未初始化
。I have this chunk of code which runs through a loop. The lower case x
var always prints correctly. The upper case X
var sometimes prints correctly, sometimes prints nan
or junk
. Why?
N.B. The data is always identical.
Link to my other SO question which shows how this is being used. BOUNTY OF 200 points!
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);
I tried running this - initialised the data using (*x)[j] = j
and removed the i==512*20
printing condition. All values came back fine. I also tried with random input data - still good. What is the nature of your input data?
(I'll look at your other question as well)
edit: I should point out I filled 512 values of the x array - your loop above only fills 10, so much of the input array is uninitialised.
这篇关于什么原因导致南错误结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!