char RoundToInt64 (float dval)
{
char val;
static float magic = 12582912.0;
dval += magic;
val = *(char *)&dval;
return val;
}
int main()
{
char e = 5;
float d = 9.67;
struct timeval ts,te;
int utime;
int i = 0;
gettimeofday(&ts,NULL);
for(i=0;i<100000;i++)
{
e = RoundToInt64 (d);
}
gettimeofday(&te,NULL);
utime = te.tv_usec - ts.tv_usec;
printf("utime is %d\n",utime);
printf("trunc d is %d\n",e);
// getchar();
return 0;
}
以上程序用gcc编译成功,运行没问题。可是用arm-gcc编译后在arm7上运行结果如下:
[/host]cd important/
[/host/important]./mmm1
utime is -240000
trunc d is 10
[/host/important]./mmm1
utime is -240000
trunc d is 10
[/host/important]./mmm1
utime is 760000
trunc d is 10
[/host/important]./mmm1
utime is -240000
trunc d is 10
不知是硬件不同的原因还是编译器的原因。高手指教!!!!!