相同的代码,VC编译和TC编译,得到不同的结果~求原因?
#include<stdio.h>#include<math.h>
main(){
short lstep,rstep,dleft,dright;
unsigned short dx,dy,ac,bc,ad,bd,ox,oy;
ac=1159;bc=1491;ox=oy=0;
while(1)
{
printf("now point at %d mm, %d mm\n",ox,oy);
puts("input dx of end point: ");
scanf("%d",&dx);
puts("input dy of end point:");
scanf("%d",&dy);
ad=(unsigned short)pow((dx+150)*(dx+150)+(1150-dy)*(1150-dy),0.5);//计算AD的长度,开方运算
printf("ad= %d mm\n",ad);
bd=(unsigned short)pow((950-dx)*(950-dx)+(1150-dy)*(1150-dy),0.5);//计算BD的长度,开方运算
printf("b d= %d mm\n",bd);
dleft=ad-ac;
dright=bd-bc;
lstep=dleft*20;
rstep=dright*20;
printf("left line move %d mm\n",dleft);
printf("right line move %d mm\n",dright);
printf("left motor must run at %d step \n",lstep);
printf("right motor must run at %d step \n",rstep);
ac=ad;bc=bd;ox=dx;oy=dy;
}
}
以上是自己写的一段计算程序~我用VC编译,得到的程序,计算的ad和bd的长度正确
用TC编译,得到的ad和bd的长度不正确
例如输入X=0,Y=0;应该得到AD=0,BD=0
这是什么原因~望有人能够解决这个问题~我这个程序必须用TC编译使用~
[此贴子已经被作者于2007-8-1 15:28:57编辑过]