一些基本错误 - 我错过了什么? (NaN的) [英] Some basic error - what am I missing? (NaNs)
问题描述
大家好......
要么我真的做了一些非常愚蠢的事情 - 或许某些地方有某些错误(优化?)
。在我的函数中:
int x1,y1,x2,y2;
float dR,dX,dY;
dR =(state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2) );
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf("%d %d%d%d \ n",state.cam1x,state.cam1y,state.cam2x,
state.cam2y);
printf("%d %d%d%d \ n",x1,y1,x2,y2);
printf("%f%f%f \ n,dX,dY,dR);
(state.xxx全局声明,函数外部为整数)
我得到:
342 224 343 225
339 215 340 215
nan nan nan
编译时没有警告。我已经查看了常见问题和其他文本,没有
运气......
John
John写道:
大家好......
要么我真的做了一些非常愚蠢的事 - 或者可能在那里是某种错误(优化?)。在我的函数中:
int x1,y1,x2,y2;
float dR,dX,dY;
dR =(state.cam1x - x1 ) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2));
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf("%d%d%d%d \ n",state.cam1x,state.cam1y,state.cam2x,
state.cam2y);
printf("%d%d%d%d \ n",x1,y1,x2,y2);
printf("%f%f %f \ n",dX,dY,dR);
(state.xxx全局声明,函数外部为整数)
我得到:/ >
342 224 343 225
339 215 340 215
南楠
编译时没有警告。我已经查看了常见问题解答和其他文本,没有
运气...
我没有看到你的碎片有什么问题提供了
,所以要么我错过了某些事情(它发生了)
或问题出在您省略的部分。请
将您的代码缩小到最小的完整程序
来证明问题,并发布完整的
程序。
-
Er*********@sun.com
jo**@jcoppens.com (约翰)写道:
要么我真的做了一些非常愚蠢的事情 - 或者某些地方可能存在某些错误(优化?)。在我的函数中:
int x1,y1,x2,y2;
float dR,dX,dY;
dR =(state.cam1x - x1 ) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2));
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf("%d%d%d%d \ n",state.cam1x,state.cam1y,state.cam2x,
state.cam2y);
printf("%d%d%d%d \ n",x1,y1,x2,y2);
printf("%f%f %f \ n",dX,dY,dR);
(state.xxx全局声明,函数外部为整数)
我得到:/ >
342 224 343 225
339 215 340 215
南楠
编译时没有警告。我已经查看了常见问题和其他文本,没有
运气......
请发布一个最小但完整的程序来证明这个问题。 />
以下程序打印
342 224 343 225
339 215 340 215
3.000000 9.500000 0.000000
在我的系统上。
Martin
#include< stdio.h>
int main(无效)
{
struct {
int cam1x;
int cam1y;
int cam2x;
int cam2y;
}州= {
342, 224,343,225
};
int x1 = 339,y1 = 215,x2 = 340,y2 = 215;
float dR,dX,dY;
dR =(state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2));
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf("%d%d%d%d \ n",state.cam1x,state.cam1y,
state.cam2x,state.cam2y);
printf("%d%d%d%d \ n",x1,y1,x2,y2);
printf(%f%f%f \ n,dX,dY,dR);
返回0;
}
John写道:大家好......
要么我真的做了一些非常愚蠢的事 - 或者也许某处有一些bug(优化?)。在我的函数中:
int x1,y1,x2,y2;
float dR,dX,dY;
dR =(state.cam1x - x1 ) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2));
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf("%d%d%d%d \ n",state.cam1x,state.cam1y,state.cam2x,
state.cam2y);
printf("%d%d%d%d \ n",x1,y1,x2,y2);
printf("%f%f %f \ n",dX,dY,dR);
(state.xxx全局声明,函数外部为整数)
我得到:/ >
342 224 343 225
339 215 340 215
南楠
编译时没有警告。我已经查看了常见问题和其他文本,没有
运气...
您的问题不在您提供给我们的信息之内:
#include< stdio.h>
struct
{
int cam1x,cam1y,cam2x ,cam2y;
}州= {342,224,343,225};
int main(无效)
{
int x1 = 339,y1 = 215,x2 = 340,y2 = 215;
浮动dR,dX,dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 *((state.cam1x - x1)+(state.cam2x - x2));
dY = 0.5 *((state.cam1y - y1)+(state.cam2y - y2));
printf(" [output] \\\
") ;
printf("%d%d%d%d \ n",state.cam1x,state.cam1y,state.cam2x,
state.cam2y) ;
printf("%d%d%d%d \ n",x1,y1,x2,y2);
printf("%f% f%f \ n",dX,dY,dR);
返回0;
}
[输出]
342 2 24 343 225
339 215 340 215
3.000000 9.500000 0.000000
-
Martin Ambuhl
Hi all...
Either I''m doing really something really stupid - or maybe there is
some bug somewhere (optimizing?). In a function I have:
int x1, y1, x2, y2;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("%d %d %d %d\n", state.cam1x, state.cam1y, state.cam2x,
state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
(state.xxx are declared globally, outside the function as integers)
I get:
342 224 343 225
339 215 340 215
nan nan nan
No warnings when compiling. I''ve looked into FAQs and other texts, no
luck...
John
John wrote:
Hi all...
Either I''m doing really something really stupid - or maybe there is
some bug somewhere (optimizing?). In a function I have:
int x1, y1, x2, y2;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("%d %d %d %d\n", state.cam1x, state.cam1y, state.cam2x,
state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
(state.xxx are declared globally, outside the function as integers)
I get:
342 224 343 225
339 215 340 215
nan nan nan
No warnings when compiling. I''ve looked into FAQs and other texts, no
luck...
I don''t see anything wrong in the fragments you''ve
provided, so either I''ve missed something (it happens)
or the problem is in the parts you''ve omitted. Please
whittle your code down to the smallest complete program
that demonstrates the problem, and post that complete
program.
--
Er*********@sun.com
jo**@jcoppens.com (John) writes:
Either I''m doing really something really stupid - or maybe there is
some bug somewhere (optimizing?). In a function I have:
int x1, y1, x2, y2;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("%d %d %d %d\n", state.cam1x, state.cam1y, state.cam2x,
state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
(state.xxx are declared globally, outside the function as integers)
I get:
342 224 343 225
339 215 340 215
nan nan nan
No warnings when compiling. I''ve looked into FAQs and other texts, no
luck...
Please post a minimal but complete program which demonstrates the problem.
The program below prints
342 224 343 225
339 215 340 215
3.000000 9.500000 0.000000
on my system.
Martin
#include <stdio.h>
int main (void)
{
struct {
int cam1x;
int cam1y;
int cam2x;
int cam2y;
} state = {
342, 224, 343, 225
};
int x1 = 339, y1 = 215, x2 = 340, y2 = 215;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("%d %d %d %d\n", state.cam1x, state.cam1y,
state.cam2x, state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
return 0;
}
John wrote:Hi all...
Either I''m doing really something really stupid - or maybe there is
some bug somewhere (optimizing?). In a function I have:
int x1, y1, x2, y2;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("%d %d %d %d\n", state.cam1x, state.cam1y, state.cam2x,
state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
(state.xxx are declared globally, outside the function as integers)
I get:
342 224 343 225
339 215 340 215
nan nan nan
No warnings when compiling. I''ve looked into FAQs and other texts, no
luck...
Your problems lie outside of the information you have given us:
#include <stdio.h>
struct
{
int cam1x, cam1y, cam2x, cam2y;
} state = { 342, 224, 343, 225};
int main(void)
{
int x1 = 339, y1 = 215, x2 = 340, y2 = 215;
float dR, dX, dY;
dR = (state.cam1x - x1) - (state.cam2x - x2);
dX = 0.5 * ((state.cam1x - x1) + (state.cam2x - x2));
dY = 0.5 * ((state.cam1y - y1) + (state.cam2y - y2));
printf("[output]\n");
printf("%d %d %d %d\n", state.cam1x, state.cam1y, state.cam2x,
state.cam2y);
printf("%d %d %d %d\n", x1, y1, x2, y2);
printf("%f %f %f\n", dX, dY, dR);
return 0;
}
[output]
342 224 343 225
339 215 340 215
3.000000 9.500000 0.000000
--
Martin Ambuhl
这篇关于一些基本错误 - 我错过了什么? (NaN的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!