double类型变量的奇怪值:-nan(0x8000000000000)

时间:2014-05-29 13:03:31

标签: double

添加后,我对“currdisk-> currangle”的值感到困惑。最初“currdisk-> currangle”的值是0.77500000000000013,但是在添加操作之后,它改为“-nan(0x8000000000000)”,有人可以解释一下吗?谢谢!以下是gdb调试的场合。

3338          currdisk->currangle += (simtime - seg->time) / currdisk->rotatetime;
(gdb) p currdisk->currangle
$28 = 0.77500000000000013
(gdb) p (simtime - seg->time) / currdisk->rotatetime
$29 = 0.00833333333333325
(gdb) p (simtime - seg->time) 
$30 = 0.092592592592591672
(gdb) p currdisk->rotatetime
$31 = 11.111111111111111
(gdb) p currdisk->currangle + (simtime - seg->time) / currdisk->ratetime
(gdb) n

(gdb) p currdisk->currangle 
$32 = -nan(0x8000000000000)
(gdb) p/x (char[8])currdisk->currangle 
$52 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8, 0xff}
(gdb) 

然后我将句子分开。

double tmp1 = (simtime - seg->time) / currdisk->rotatetime; 
currdisk->currangle += tmp1

currdisk-> currangle的值是正常的。

tmp1 = (simtime - seg->time) / currdisk->rotatetime;
currdisk->currangle += tmp1;

以上代码也可以在以后的调用中导致NaN。

所以我走进大会。

tmp1 = (simtime - seg->time) / currdisk->rotatetime;
0x0808fdf4  <disk_buffer_sector_done+559>:  fldl   0x80b2208
0x0808fdfa  <disk_buffer_sector_done+565>:  mov    -0x38(%ebp),%eax
0x0808fdfd  <disk_buffer_sector_done+568>:  fldl   (%eax)

...这里,%eax的内容是0x80bdfeb,这是seg-> time的地址。 在执行上述“fldl(%eax)”之后,寄存器st0的内容为0x8000000000000000,表示NaN。 因此,NaN会传播到以下说明中。这是关键问题。 代码:

0x0808fdff  <disk_buffer_sector_done+570>:  fsubrp %st,%st(1)
0x0808fe01  <disk_buffer_sector_done+572>:  mov    0x8(%ebp),%eax
0x0808fe04  <disk_buffer_sector_done+575>:  fldl   0xc4(%eax)
0x0808fe0a  <disk_buffer_sector_done+581>:  fdivrp %st,%st(1)
0x0808fe0c  <disk_buffer_sector_done+583>:  fstpl  -0x28(%ebp)

0 个答案:

没有答案