当前位置:网站首页>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
边栏推荐
猜你喜欢
Embedded system driver primary [2] - based on character device driver _ basic framework
"Second Uncle" is popular, do you know the basic elements of "exploding" short videos from the media?
How to improve the originality of self-media creation and create popular works?
玉溪卷烟厂通过正确选择时序数据库 轻松应对超万亿行数据
方舟生存进化淘宝面板服务器是怎么一回事?
[C language] Explicit array solution (1)
【C语言】手撕循环结构 ——do...while语句及循环练习题(1)
Summer training camp-week2 graph theory
嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架
MySQL - ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
随机推荐
鲲鹏devkit & boostkit
rhce第三天作业
Embedded system driver primary [2] - based on character device driver _ basic framework
The uniapp/applet onload method executes the interpretation every time the page is opened
CVE-2020-27986(Sonarqube敏感信息泄漏) 漏洞修复
社区收藏缓存设计重构实战
wait() ,notify(),notifyAll()以及wait()与sleep()比较
Detailed explanation of ORACLE expdp/impdp
Detailed explanation of stored procedures
SQL函数 USER
Flutter 实现光影变换的立体旋转效果
wx-wow(微信小程序动效库)
【C语言】夏日一题 —— 求最大公约数和最小公倍数
Selenium本地打开远程浏览器
[C language] Analysis of function recursion (2)
80篇国产数据库实操文档汇总(含TiDB、达梦、openGauss等)
tinymce 如何实现动态国际化
rust使用mysql插入数据
攻防世界----unfinish
打破文件锁限制,以存储力量助力企业增长新动力