如何浮点数被存储在内存中? [英] How are floating point numbers are stored in memory?

查看:118
本文介绍了如何浮点数被存储在内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过他们存储在尾数和指数

I've read that they're stored in the form of mantissa and exponent

我读过<一个href=\"http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point_re$p$psentation.html\">this文件但我什么都听不懂。

I've read this document but I could not understand anything.

推荐答案

要了解它们是如何存储,你必须先了解它们是什么,什么样的,他们的目的是处理的值。

To understand how they are stored, you must first understand what they are and what kind of values they are intended to handle.

不像整数,浮点值的目的是重新present极小值以及非常大。对于普通的32位浮点值,这相当于值的范围从 1.175494351 * 10 ^ -38 3.40282347 * 10 ^ + 38

Unlike integers, a floating-point value is intended to represent extremely small values as well as extremely large. For normal 32-bit floating-point values, this corresponds to values in the range from 1.175494351 * 10^-38 to 3.40282347 * 10^+38.

显然,只用32位,这是不可能的每一个数字存储在这样的数字。

Clearly, using only 32 bits, it's not possible to store every digit in such numbers.

当它涉及到重新presentation,你可以看到一切正常浮点数作为值范围为1.0(几乎)2.0,用两个功率缩放。所以1.0是,只需 1.0 * 2 ^ 0 。 2.0 1.0 * 2 ^ 1 。 -5.0是 -1.25 * 2 ^ 2

When it comes to the representation, you can see all normal floating-point numbers as a value in the range 1.0 to (almost) 2.0, scaled with a power of two. So 1.0 is, simply 1.0 * 2^0. 2.0 is 1.0 * 2^1. -5.0 is -1.25 * 2^2.

所以,这是需要的EN code这一点,尽可能高效地?什么是我们真正需要的?

So, that is needed to encode this, as efficiently as possible? What do we really need?


  • 除权pression的迹象。

  • 的指数

  • 在范围1.0至(几乎)2.0的值。这被称为尾数即有效数字。

这是EN codeD如下,根据IEEE-754浮点标准。

This is encoded as follows, according to the IEEE-754 floating-point standard.


  • 的标志是一个位。

  • 的指数存储为一个无符号整数,用于32位浮点值,此字段为8比特。 1重presents最小的指数,所有的人 - 1是最大的。 (0,所有的人是用来连接code特殊值,见下文)的值在中间(127,在32位的情况下)再presents为零,这也被称为的偏置

  • 当在尾数寻找(1.0之间的值(几乎)2.0),人们可以看出所有可能的值开始一个1(无论是在十进制和二进制重新presentation)。这意味着,它没有点存放。的二进制数字的其余部分存储在一个整数字段,在32位的情况下,这字段是23位。

在除了正常的浮点值,也有一些特殊值:

In addition to the normal floating-point values, there are a number of special values:


  • 零是带两个指数和尾数是零codeD。符号位用于重新present加零,减零。当操作的结果是非常小的一个负零是有用的,但它仍然是重要的是知道从哪个方向来自操作。

  • 加号和减号无穷 - 再$ P $使用全一指数和零尾数场psented

  • 使用全一指数和非零尾数psented重新$ P $ -
  • 不是数字(NAN)。
  • 非规范化数 - 数比最小的正常数量较小。重新$ P $使用零指数域和非零尾数psented。这些号码的特殊的是,precision(即数字的值可以包含数量)将下降值变得越小,这只是因为没有在尾数余地它们。

最后,以下是具体例一小撮(所有值都以十六进制):

Finally, the following is a handful of concrete examples (all values are in hex):


  • 1.0:3f800000

  • -1234.0:c49a4000

  • 100000000000000000000000.0:65a96816

这篇关于如何浮点数被存储在内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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