本文介绍了的显著位数浮点型数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C型浮动的说明提到的显著位数为 6 。不过,

The description for type float in C mentions that the number of significant digits is 6. However,

float f = 12345.6;

,然后使用printf()的不打印 12345.6 ,它打印在打印 12345.599609 。那么什么是6位数显著(或15的情况下,双击),意味着一个浮点类型?

and then printing it using printf() does not print 12345.6, it prints 12345.599609. So what does "6 significant digits" (or "15 in case of a double") mean for a floating point type?

推荐答案

按照,不是所有的十进制数可以存储恰好在存储器中。取决于再presentation的大小,误差可以得到一定的最大值。对于浮动这是 0.0001%(6显著位数= 10 ^ -6 = 10 ^ -4%)。

According to the standard, not all decimal number can be stored exactly in memory. Depending on the size of the representation, the error can get to a certain maximum. For float this is 0.0001% (6 significant digits = 10^-6 = 10^-4 %).

在您的情况下误差。(12345.6 - 12345.599609)/ 12345.6 = 3.16e-08 远远超过了彩车的最大误差较低

In your case the error is (12345.6 - 12345.599609) / 12345.6 = 3.16e-08 far lower than the maximum error for floats.

这篇关于的显著位数浮点型数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:38