双精度 [英] double and accuracy

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

问题描述

使用 long double 我得到 18/19 = 0.947368421052631578 ... 947368421052631578 是重复的十进制。使用 double 我得到 0.947368421052631526 ... 然而,前者是正确的。为什么会出现这样不正确的结果?

Using long double I get 18/19 = 0.947368421052631578..., and 947368421052631578 is the repeating decimal. Using double I get 0.947368421052631526... However, the former is correct. Why such an incorrect result?

感谢您的帮助。

推荐答案

A double 通常提供16(±1)个十进制数字。您的示例显示:

A double typically provides 16(±1) decimal digits. Your example shows this:

     4   8  12  16
     v   v   v   v
0.947368421052631578 long double
0.947368421052631526 double

答案同意16位数字。这是应该预期的。另请注意,C标准中不能保证 long double double 更精确。

The answers agree to 16 digits. This is what should be expected. Also note that there's no guarantee in the C Standard that a long double has more precision than a double.

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

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