是最显著十进制数字precision可转换为二进制和回十进制没有意义的6或7.225的损失? [英] Is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance 6 or 7.225?

查看:157
本文介绍了是最显著十进制数字precision可转换为二进制和回十进制没有意义的6或7.225的损失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到两个不同的precision公式浮点数。


  

⌊(N-1)登录 10 (2)⌋= 6十进制数字(单precision)



  

N日志 10 (2)asymp; 7.225小数位数(单precision)


其中的 N = 24 有效位的(单precision)

第一个公式是在 IEEE标准4页的顶部发现754二进制浮点运算以书面, W. Kahan的教授

第二个公式是在维基百科的文章单$ P $发现pcision浮点格式根据第的 IEEE 754单precision二进制浮点格式:binary32

有关第一个公式,W. Kahan的教授说。


  

如果一个十进制字符串最多6 SIG。十进制转换成单,再转换回相同数量的技术联盟。十进制,
  那么最终的字符串应匹配原始。


有关第二个公式,维基百科说


  

...总precision为24位(相当于日志 10 (2 24 )≈ 7.225小数位数)。


这两个公式(6和7.225十进制数字)的结果是不同的,我希望他们是一样的,因为我认为他们都注定要重新present最显著十进制数字,可以被转换成浮动 - 点二进制,然后再转换回小数与相同数量的显著十进制数字,它开始。

为什么这两个数字不同,什么是最显著十进制数字precision可转换为二进制和回十进制没有意义?损耗


解决方案

  

什么是最显著十进制数字precision,可以
  转换成二进制和回十进制没有意义的丧失?


最显著十进制数字precision可转换为二进制和回无意义的损失小数(单precision浮点数或24位)是6位十进制数。



  这两个数字

为什么不同...


中的数字6和7.225不同,因为它们定义两个不同的事情。 6是最十进制数字可以往返式操作。 7.225是十进制数字precision一个24位二进制整数的大致数量,因为24位的二进制整数可以有7或8位十进制数字取决于其特定的价值。

7.225使用特定的二进制整数配方被发现。


  

D <子>规范 = B&middot;日志 10 (2)&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;(D 规范
  =特定的十进制数字,B =位)


然而,你通常需要知道,对于一个b比特整数的最小和最大十进制数。下面的公式用于查找最小和最大十进制数字(7和8分别为24比特)的特定的二进制整数的


  

D <子>分 =⌈(B-1)&middot;日志 10 (2)⌉&NBSP;&NBSP;&NBSP;&NBSP;( ð<子>分
  =分十进制数字,B =位,⌈x⌉=最小整数≥X)


  
  

D 最大值 = ⌈b·log10(2)⌉         (dmax
  = MAX十进制数字,B =位,⌈x⌉=最小整数≥X)


要了解更多关于这些公式是如何得出的,读的十进制数字对一个二进制整数,由Rick里根写的数量。

这是一切都很好,但你可能会问,为什么是6对往返转换最十进制数字,如果你说的小数位数为24位数字跨度为7〜8?

答案是 - 因为上面的公式只对工作的的整数并没有浮点数

每一个十进制整数在二进制的精确值。然而,同样不能说每一个十进制浮点数。以 .1 为例。 .1 二进制是多少 0.000110011001100 ... ,这是一个重复的或反复的二进制文件。这可能会产生舍入误差。

此外,它需要一个以上位以重新present十进制比它重新present同样重要的十进制整数浮点数。这是因为,浮点数更precise越接近它们是0,而较少precise进一步它们从0因此,邻近的最小和最大值范围的许多浮点数( Ë<子>分 = -126和E 最大值 = +127为单precision)失去precision的1位,由于舍入误差。直观地看到这一点,看看什么每台计算机程序员应该知道有关浮点,第1部分,由Josh哈伯曼写的。

此外,至少有 784757 正七位小数往返转换后无法保留其原始值。无法生存的往返这样一些的一个实例是 8.589973e9 。这是一种不保留其原始值的最小正数。

下面是你应该使用浮点数precision的公式,会给你往返转换是6位小数。


  

D 最大值 =⌊(B-1)·日志 10 (2)⌋&NBSP;&NBSP;&NBSP;&NBSP;(四最大值
  = MAX十进制数字,B =位,⌊x⌋=最大的整数≤X)


要了解更多有关这个公式是如何得出的,读的数字所需的数目对于,还写了里克·里根往返转换。里克确实显示出有严格的证据引用公式推导了出色的工作。


因此​​,你可以利用以建设性的方式上面的公式;如果你了解他们的工作,你可以将它们应用到使用浮点数据类型的任何编程语言。你所知道的是,你的浮点数据类型有显著的位数,你可以找到各自的小数位数,你可以指望有一个往返转换后没有意义的损失。

I've come across two different precision formulas for floating-point numbers.

⌊(N-1) log10(2)⌋ = 6 decimal digits (Single-precision)

and

N log10(2) ≈ 7.225 decimal digits (Single-precision)

Where N = 24 Significant bits (Single-precision)

The first formula is found at the top of page 4 of "IEEE Standard 754 for Binary Floating-Point Arithmetic" written by, Professor W. Kahan.

The second formula is found on the Wikipedia article "Single-precision floating-point format" under section IEEE 754 single-precision binary floating-point format: binary32.

For the first formula, Professor W. Kahan says

If a decimal string with at most 6 sig. dec. is converted to Single and then converted back to the same number of sig. dec., then the final string should match the original.

For the second formula, Wikipedia says

...the total precision is 24 bits (equivalent to log10(224) ≈ 7.225 decimal digits).

The results of both formulas (6 and 7.225 decimal digits) are different, and I expected them to be the same because I assumed they both were meant to represent the most significant decimal digits which can be converted to floating-point binary and then converted back to decimal with the same number of significant decimal digits that it started with.

Why do these two numbers differ, and what is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance?

解决方案

what is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance?

The most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance (for single-precision floating-point numbers or 24-bits) is 6 decimal digits.


Why do these two numbers differ...

The numbers 6 and 7.225 differ, because they define two different things. 6 is the most decimal digits that can be round-tripped. 7.225 is the approximate number of decimal digits precision for a 24-bit binary integer because a 24-bit binary integer can have 7 or 8 decimal digits depending on its specific value.

7.225 was found using the specific binary integer formula.

dspec = b·log10(2)             (dspec = specific decimal digits, b = bits)

However, what you normally need to know, are the minimum and maximum decimal digits for a b-bit integer. The following formulas are used to find the min and max decimal digits (7 and 8 respectively for 24-bits) of a specific binary integer.

dmin = ⌈(b-1)·log10(2)⌉    (dmin = min decimal digits, b = bits, ⌈x⌉ = smallest integer ≥ x)

dmax = ⌈b·log10(2)⌉         (dmax = max decimal digits, b = bits, ⌈x⌉ = smallest integer ≥ x)

To learn more about how these formulas are derived, read Number of Decimal Digits In a Binary Integer, written by Rick Regan.

This is all well and good, but you may ask, why is 6 the most decimal digits for a round-trip conversion if you say that the span of decimal digits for a 24-bit number is 7 to 8?

The answer is — because the above formulas only work for integers and not floating-point numbers!

Every decimal integer has an exact value in binary. However, the same cannot be said for every decimal floating-point number. Take .1 for example. .1 in binary is the number 0.000110011001100..., which is a repeating or recurring binary. This can produce rounding error.

Moreover, it takes one more bit to represent a decimal floating-point number than it does to represent a decimal integer of equal significance. This is because floating-point numbers are more precise the closer they are to 0, and less precise the further they are from 0. Because of this, many floating-point numbers near the minimum and maximum value ranges (emin = -126 and emax = +127 for single-precision) lose 1 bit of precision due to rounding error. To see this visually, look at What every computer programmer should know about floating point, part 1, written by Josh Haberman.

Furthermore, there are at least 784,757 positive seven-digit decimal numbers that cannot retain their original value after a round-trip conversion. An example of such a number that cannot survive the round-trip is 8.589973e9. This is the smallest positive number that does not retain its original value.

Here's the formula that you should be using for floating-point number precision that will give you 6 decimal digits for round-trip conversion.

dmax = ⌊(b-1)·log10(2)⌋    (dmax = max decimal digits, b = bits, ⌊x⌋ = largest integer ≤ x)

To learn more about how this formula is derived, read Number of Digits Required For Round-Trip Conversions, also written by Rick Regan. Rick does an excellent job showing the formulas derivation with references to rigorous proofs.


As a result, you can utilize the above formulas in a constructive way; if you understand how they work, you can apply them to any programming language that uses floating-point data types. All you have to know is the number of significant bits that your floating-point data type has, and you can find their respective number of decimal digits that you can count on to have no loss of significance after a round-trip conversion.

这篇关于是最显著十进制数字precision可转换为二进制和回十进制没有意义的6或7.225的损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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