How It Works
Toggle navigation
How It Works
Home
About Me
Archives
Tags
浮点数精度问题笔记
2017-05-21 11:41:53
439
0
0
ochapman
#前言 读《深入理解计算机系统》,里面有一个关于浮点数的造成28死亡的事件 #事件背景 ``` On February 25, 1991, during the Gulf War, a Patriot missile defense system let a Scud get through. It hit a barracks, killing 28 people. The problem was in the differencing of floating point numbers obtained by converting and scaling an integer timing register. The GAO report has less than the full story. For that see Skeel's excellent article. ``` #原因 0.1秒使用二进制表示时,是循环小数 使用24位的寄存器存储时间,精度不够 时间转化为整数保存 修复是通过两个24位的寄存器来保存 但是没有修复所有的地方 代码使用汇编编写,维护困难。 #误差是如何计算的 使用整数保存24位的寄存器,将丢掉32位后面的数值。 24位保存的数值 ``` 0.00011001100110011001100 ``` 转化为32位时,将丢弃 ``` 0.0000000000000000000000011001100 ``` 转化为10进制,则为 ``` 0.000000095 ``` 当100小时,将有0.34的误差 ``` 0.000000095×100×60×60×10=0.34 ``` 而飞毛腿导弹的速度是1676m/s。0.34秒,将有569.84m的误差 #参考 1. Robert Skell的文章 https://w3.ual.es/~plopez/docencia/itis/patriot.htm 2. 讲得最详细 http://seeri.etsu.edu/SECodeCases/ethicsC/PatriotMissile.htm
Pre:
Firefox: change means pain or dead
Next:
janus是怎么做频率限制
0
likes
439
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Table of content