我什至不确定我是在问一个问题,这次我找到了一种“迂回”的方式,但是……我花了几天时间才意识到这是问题所在,而且……好吧,其他时候我可能不会能够绕过它......还有其他人来过这个吗?比较实际上相等的双精度类型变量时,结果是“>”...
printf("compare: %ld ?? %ld\n", (double)( radii(nowX,nowY)*irange2 ),(double)(Rad2*irange2)); getchar();
if( (double)(radii(nowX,nowY)*irange2)<(double)(Rad2*irange2) ) printf("*** < ***\n");
if( (double)(radii(nowX,nowY)*irange2)>(double)(Rad2*irange2) ) printf("*** > ***\n");
if( (double)(radii(nowX,nowY)*irange2)==(double)(Rad2*irange2) ) printf("*** == ***\n")
printf("SECOND = %d\n", ((double)(radii(nowX,nowY)*irange2))<= ( (double)(Rad2*irange2)
输出:
compare: 1509949.440000 ?? 1509949.440000
*** > ***
SECOND = 0
printf("compare: %ld ?? %ld\n", (long)( radii(nowX,nowY)*irange2 ), (long)(Rad2*irange2)); getchar();
if( (long)(radii(nowX,nowY)*irange2)<(long)(Rad2*irange2) ) printf("*** < ***\n");
if( (long)(radii(nowX,nowY)*irange2)>(long)(Rad2*irange2) ) printf("*** > ***\n");
if( (long)(radii(nowX,nowY)*irange2)==(long)(Rad2*irange2) ) printf("*** == ***\n")
printf("SECOND = %d\n", ((long)(radii(nowX,nowY)*irange2))<= ( (long)(Rad2*irange2) ) ); getchar();
输出:
compare: 1509949 ?? 1509949
*** == ***
SECOND = 1