帮助双精度加法 [英] Help in double precision addition

查看:125
本文介绍了帮助双精度加法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试我的一些代码,在javascript中我添加.1 + .2并且它给了我.30000000000000004而不是.3。我不明白这一点。
但是当我添加.1 + .3时,它给了我.4。我用Google搜索并找到了关于Double Precision添加的内容。但我不知道它是什么。

I was testing some of my code, in javascript I added .1+.2 and it gives me .30000000000000004 instead of .3 . I don't understand this. But when I added .1+.3 it gives me .4. I googled it and find its something about Double Precision addition. But I don't know what it is.

推荐答案

这是强制性链接:每个计算机科学家应该知道的关于浮点运算的知识

基本上,有许多基数为10的数字无法用大多数计算机使用的浮点格式精确表示,因此您会遇到类似您突出显示的问题。

Basically, there are many base 10 numbers that cannot be exactly represented in the floating point format used by most computers, so you'll get issues like the ones you highlight.

这篇关于帮助双精度加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆