当前位置:网站首页>Why does a four-byte float represent a wider range than an eight-byte long
Why does a four-byte float represent a wider range than an eight-byte long
2022-08-02 13:51:00 【To learn programming small parties】
There are two types of floating point numbers in Java:
Type name Storage size Value range
float (single precision) 4 bytes (32bit)
-3.403E38 ~ 3.403E38
double(double precision) 8 bytes (64bit)
-1.798E308 ~ 1.798E308
Storage structure
Floating-point numbers are stored in three parts:
sign bit
exponent bit
mantissa bit (significand)
32-bit single-precision floating-point number = 1 sign bit + 8 exponent bits + 23 significant digits
64-bit double-precision floating-point number = 1 sign bit + 11 exponent bits + 52 significant digits
The computer stores floating point numbers
Sign bit: 1 means negative value, 0 means positive value
Exponent bit: The exponent range of float is 8 bits (-128~+127), while the exponent range of double is 11 bits (-1024~+1023), and the exponent bits are divided in two's complement form.
The negative exponent determines the non-zero number with the smallest absolute value that the floating-point number can express; while the positive exponent determines the number with the largest absolute value that the floating-point number can express, that is, determines the value range of the floating-point number.
Mantissa: The precision of float and double is determined by the number of digits in the mantissa.Floating-point numbers are stored in memory according to scientific notation, and the integer part is always an implicit "1". Since it is immutable, it cannot affect the precision.
float: 2^23 = 8388608, a total of seven digits, since the leftmost 1 is omitted, which means that it can represent up to 8 digits: 2*8388608 = 16777216 .There are 8 significant digits, but 7 digits are absolutely guaranteed, that is, the precision of float is 7~8 significant digits; double: 2^52 = 4503599627370496, a total of 16 digits, and the precision of double is 16~17 digits.
IEEE Floating Point Standard
According to the IEEE Floating Point Standard, any binary floating point number N can be represented in the following form:
32-bit floating point numbers
N = (-1)^s × (1.M ) × 2^(E-127)
64-bit floating point numbers
N = (-1)^s × (1.M ) × 2^(E-1023)
Sign (sign) s represents the sign bit, when s=0, N is a positive number; when s=1, N is a negative number.
Mantissa (significand) M is a binary decimal, 1≤M<2.
Exponent bit (exponent) The role of E is to weight floating-point numbers, this weight is 2 to the power of E (may be negative)
The E order code occupies 8 bits, and the order sign adopts an implicit method, that is, usingFrameshift method to represent positive and negative exponents.The code-shift method is more convenient for the comparison of the two exponents and the order-to-order operation, because the larger the exponent value is, the larger the exponent value is.In this way, when the true value of the exponent e of the floating point number is changed to the order code E, the exponent e should be added with a fixed offset value of 127 (01111111), that is, E=e+127.
Basic data types (8 types in 4 categories), integer type, floating point type, character type, boolean type.
Integer type:
long 8 bytes (64bit) -2^63 ---- 2^63-1
32-bit floating point numbers
float Four bytes (32bit) -2^127--2^127
Integers and floats differ between underlying storage, so a 4-bit float can represent a larger range than an 8-bit long
边栏推荐
- 删除链表的节点
- SQL函数 TRUNCATE
- Differences and concepts between software testing and hardware testing
- 自媒体创作怎样提高原创度,打造爆款作品?
- 【C语言】手撕循环结构 ——do...while语句及循环练习题(1)
- ttl电平与rs232电平转换电路(232电平定义)
- 【C语言】函数哪些事儿,你真的get到了吗?(1)
- [typescript] Use the RangePicker component in antd to implement time limit the previous year (365 days) of the current time
- 【typescript】使用antd中RangePicker组件实现时间限制 当前时间的前一年(365天)
- 【C语言】手撕循环结构 —— for语句
猜你喜欢
随机推荐
供应磷脂-聚乙二醇-羧基,DSPE-PEG-COOH,DSPE-PEG-Acid,MW:5000
科研试剂DSPE-PEG-VIP,二硬脂酰基磷脂酰乙醇胺-聚乙二醇-血管活性肠肽VIP
机器学习——交叉验证法
二极管及其应用
.Net 5.0 Quick Start Redis
rust使用mysql插入数据
80篇国产数据库实操文档汇总(含TiDB、达梦、openGauss等)
WPF效果第一百九十三篇之登录实现
智能指针-使用、避坑和实现
面试官:可以谈谈乐观锁和悲观锁吗
Seata Distributed Transaction
CVE-2020-27986 (Sonarqube sensitive information leak) vulnerability fix
In-depth analysis and use of Ribbon load balancing
【C语言】手把手带你写游戏 —— 猜数字
苏州大学:从 PostgreSQL 到 TDengine
WeChat applet getPhoneNumber interface code=40013
Embedded system driver primary [2] - based on character device driver _ basic framework
C语言结构体(入门)
【ONE·Data || 排序入门】
Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法