本文介绍了double类型变量的奇怪值:-nan(0x8000000000000)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 添加操作后,我对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->时间) $ 30 = 0 。 092592592592591672 (gdb)p currdisk-> rotatetime $ 31 = 11 。 111111111111111 (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) 然后我改变 currdisk-> currangle + =(simtime - seg-> time)/ currdisk-> rotatetime; to double tmp1 =( simtime - seg-> time)/ currdisk-> rotatetime; currdisk-> currangle + = tmp1; currdisk-> currangle的值是正常的。任何人都可以解释这个令人困惑的现象吗?解决方案 28 = 0 。 77500000000000013 (gdb)p(simtime - seg->时间)/ currdisk-> rotatetime 29 = 0 。 00833333333333325 (gdb)p(simtime - seg-> time) 30 = 0 。 092592592592591672 (gdb)p currdisk-> rotatetime I am confused by the value of "currdisk->currangle" after adding operation. Initially the value of "currdisk->currangle" is 0.77500000000000013, but after adding operation, it's changed to "-nan(0x8000000000000)", Can anyone explain ? Thanks! The following is the occasion of gdb debugging.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) 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)Then I changecurrdisk->currangle += (simtime - seg->time) / currdisk->rotatetime ;todouble tmp1 = (simtime - seg->time) / currdisk->rotatetime;currdisk->currangle += tmp1;The value of currdisk->currangle is normal. Can anyone explain the confusing phenomenon ? 解决方案 28 = 0.77500000000000013(gdb) p (simtime - seg->time) / currdisk->rotatetime29 = 0.00833333333333325(gdb) p (simtime - seg->time)30 = 0.092592592592591672(gdb) p currdisk->rotatetime 这篇关于double类型变量的奇怪值:-nan(0x8000000000000)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-31 17:16