简体   繁体   English

使用浮点二进制格式的变量如何存储值 0.0

[英]How does a variable using a Floating-point binary format stores the value 0.0

Basically I'm confused right now and can't find anything helpful on stackoverflow or through google search.基本上我现在很困惑,在 stackoverflow 或通过谷歌搜索找不到任何有用的东西。 I've been reading about how computers store differents data types in binary format to better understand C programming and general knowledge about computer science.我一直在阅读有关计算机如何以二进制格式存储不同数据类型的信息,以便更好地理解 C 编程和有关计算机科学的一般知识。 I think I understand how floating-point numbers work but from what I understood the first bit in front of the decimal point (or binary point idk) isn't included because it is supposedly always 1 since we move the decimal point behind the first bit with a value of 1 from left to right.我想我理解浮点数是如何工作的,但据我所知,小数点前的第一位(或二进制点 idk)不包括在内,因为它应该总是 1,因为我们将小数点移到了第一位后面从左到右的值为 1。 In that case, since we don't store the first bit, how would we be able to differentiate a floating-point variable storing the value 1.0 from 0.0.在那种情况下,由于我们不存储第一位,我们如何能够区分存储值 1.0 和 0.0 的浮点变量。

在此处输入图像描述

Ps.附言。 don't hesitate to edit this post if needed.如果需要,请不要犹豫编辑这篇文章。 English is not my first language.英语不是我的母语。

... first bit in front of... binary point... isn't included because it is supposedly always 1... ...前面的第一位...二进制点...不包括在内,因为它应该总是 1...

Not always .总是

With common floating point formats, like float32 , when the biased exponent is a (0), the significand (erroneously called the mantissa) has a leading 0 and not 1 .对于常见的浮点格式,如float32 ,当偏置指数为 (0) 时,有效数(错误地称为尾数)具有前导0而不是1 At that point the biased exponent encodes differently too.在这一点上,偏置指数编码也不同。

"Zero" is usually encoded as an all zero-bit pattern. “零”通常被编码为全零位模式。

            v--- Implied bit
0 11111110 (1) 111_1111_1111_1111_1111_1111 Maximum value (~3.4e38)
0 01111111 (1) 000_0000_0000_0000_0000_0000 1.0
0 00000001 (1) 000_0000_0000_0000_0000_0000 smallest non-zero "normal" (~1.18e-38)
0 00000000 (0) 111_1111_1111_1111_1111_1111 largest  "sub-normal" (~1.18e-38)
0 00000000 (0) 000_0000_0000_0000_0000_0001 smallest "sub-normal" (~1.40e-45)
0 00000000 (0) 000_0000_0000_0000_0000_0000 zero

-0.0, when supported is the same as 0.0 with a 1 in the sign bit place. -0.0,当支持时与 0.0 相同,符号位位置为 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM