Numerical issue with `foldl` and `foldr` in Haskell

情到浓时终转凉″ 提交于 2019-12-06 04:36:37

In general, the order in which floating point values are added is important. An entry point for own research could be http://en.wikipedia.org/wiki/Loss_of_significance . To summarize the basic caveat, in an oversimplified form:

Due to the limited number of significant bits, you have to assume something like

 100000000000000000.0 + 1.0 = 100000000000000000.0

in floating-point computations. Consequently, when computing

  100000000000000000.0 
+                  1.0 
- 100000000000000000.0

the result will be 0.0 - and thus, be different from

  100000000000000000.0 
- 100000000000000000.0
+                  1.0 

where the result will be 1.0.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!