浮点精度位 [英] Float precision bits

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

问题描述

在这个维基文章中,显示了23位精度,8位指数, 1 for sign



其中是隐藏的第24位浮点型,使(23 + 1)7个有效位数?

解决方案

浮点数通常是标准化的。比如,考虑一下我们大多数人在学校学到的科学记数法。您始终对指数进行缩放,以便小数点前一位。例如,而不是123.456,你写的是1.23456x10 2

通常处理计算机上的浮点(几乎是 1 ):数字是标准化的,所以在二进制点之前只有一个数字(二进制​​点,因为大多数工作在二进制而不是十进制)。有一个区别:在二进制的情况下,这意味着小数点之前的数字必须是一个 1 。由于它总是一个 1 ,所以没有必要存储这个位。为了在每个浮点数中节省一点存储空间, 1 位是隐含的而不是被存储的。



像往常一样,情况只是比这更多。主要区别是非规格化的数字。例如,考虑一下你是否在做科学记数法,但是你只能使用从-99到+99的指数。如果你想存储一个数字,比如说1.234 * 10 -102 ,那么你不能直接这样做,所以它可能会舍入到0。



非规范化的数字给你一个处理这个问题的方法。使用非规格化的数字,您可以将其存储为0.001234 * 10 -99 。假设(如通常情况下在计算机上)尾数和指数的位数都是有限的,这会损失一些精度,但仍然可以避免抛弃所有的精度, code> 0 。






1 从技术上讲,有分歧,但对涉及的基本认识没有任何影响。

In this wiki article it shows 23 bits for precision, 8 for exponent, and 1 for sign

Where is the hidden 24th bit in float type that makes (23+1) for 7 significand digits?

解决方案

Floating point numbers are usually normalized. Consider, for example, scientific notation as most of us learned it in school. You always scale the exponent so there's exactly one digit before the decimal point. For example, instead of 123.456, you write 1.23456x102.

Floating point on a computer is normally handled (almost1) the same way: numbers are normalized so there's exactly one digit before the binary point (binary point since most work in binary instead of decimal). There's one difference though: in the case of binary, that means the digit before the decimal point must be a 1. Since it's always a 1, there's no real need to store that bit. To save a bit of storage in each floating point number, that 1 bit is implicit instead of being stored.

As usual, there's just a bit more to the situation than that though. The main difference is denormalized numbers. Consider, for example, if you were doing scientific notation but you could only use exponents from -99 to +99. If you wanted to store a number like, say, 1.234*10-102, you wouldn't be able to do that directly, so it would probably just get rounded down to 0.

Denormalized numbers give you a way to deal with that. Using a denormalized number, you'd store that as 0.001234*10-99. Assuming (as is normally the case on a computer) that the number of digits for the mantissa and exponent are each limited, this loses some precision, but still avoids throwing away all the precision and just calling it 0.


1 Technically, there are differences, but they make no difference to the basic understanding involved.

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

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