浮点数的意义与精度损失之间的关系是什么? [英] What is the relationship between digits of significance and precision loss in floating point numbers?

查看:325
本文介绍了浮点数的意义与精度损失之间的关系是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直试图围绕浮点数的有效位数和精度的相对损失之间的关系,但我似乎无法理解它。我刚才读了一篇文章,说要做以下事情:


  1. 设置一个浮点值为2147483647.您会看到它的值实际上是2147483648

  2. 从浮点数中减去64,您将看到该操作正确

  3. 从浮点值减去65,您将看到您实际上现在有2147483520,这意味着它实际上减去了128。

那么为什么在128位有10位有效数字?我知道如何存储浮点数(1位为符号,8位为指数,23位为尾数),并理解如果您假设所有整数都会自动在浮点数据结构中找到精确的家园,您将如何失去精度,不知道128从哪里来。我的直觉告诉我,我在正确的轨道上,但我希望有人能够为我清除这个。



我最初认为可能花车之间的距离是2 ^(n-1),其中n是有效位数,但是这并不是真的。

谢谢!

解决方案

两个相邻浮点数之间的距离是2 ^(1-n + e) e 是尾数(AKA有效数)中的真位数和位数。存储的指数不是真正的指数,它有一个偏差。对于IEEE-754浮点数,这是 127 (对于标准化数字)。所以,正如Peter O所说,距离取决于指数。

So I have been trying to wrap by head around the relation between the number of significant digits in a floating point number and the relative loss of precision, but I just can't seem to make sense of it. I was reading an article earlier that said to do the following:

  1. Set a float to a value of 2147483647. You will see that its value is actually 2147483648
  2. Subtract 64 from the float and you will see that the operation is correct
  3. Subtract 65 from the float and you will see that you actually now have 2147483520, meaning that it actually subtracted 128.

So why is this 128 when there are 10 significant digits? I understand how floats are stored (1 bit for sign, 8 bits for exponent, 23 bits for mantissa) and understand how you will lose precision if you assume that all integers will automatically find exact homes in a float data structure, but I don't understand where the 128 comes from. My intuition tells me that I'm on the right track, but I'm hoping that someone may be able to clear this up for me.

I initially thought that the distance between possible floats was 2 ^ (n-1) where n was the number of significant digits, but this did not hold true.

Thank you!

解决方案

The "distance" between two adjacent floating point numbers is 2^(1-n+e), where e is the true exponent and n the number of bits in the mantissa (AKA significand). The exponent stored is not the true exponent, it has a bias. For IEEE-754 floats, this is 127 (for normalized numbers). So, as Peter O said, the distance depends on the exponent.

这篇关于浮点数的意义与精度损失之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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