当前位置:网站首页>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
边栏推荐
- 二分查找 && 树
- 乐心湖‘s Blog——MySQL入门到精通 —— 囊括 MySQL 入门 以及 SQL 语句优化 —— 索引原理 —— 性能分析 —— 存储引擎特点以及选择 —— 面试题
- HALCON: 内存管理(Memory Management)
- 短视频美食自媒体怎么做?5步教你快速上手
- els 长条方块变形条件、边界碰撞判定
- 国产 GPU 创业潮 喧嚣下的资本游戏
- 【C语言】手撕循环结构 —— for语句
- CVE-2020-27986 (Sonarqube sensitive information leak) vulnerability fix
- 【C语言】手撕循环结构 —— while语句
- 苹果,与Web3 “八字不合”
猜你喜欢
随机推荐
【C语言】夏日一题 —— 求最大公约数和最小公倍数
Markdown怎么加入emoji
Get out of the machine learning world forever!
Interviewer: Can you talk about optimistic locking and pessimistic locking?
CSDN(成长一夏竞赛)- 最大数
【C语言】虐打循环练习题(2)
嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架
SQL函数 UCASE
二极管及其应用
腾讯安全发布Tencent Cloud EdgeOne,为企业出海打造安全加速一体化服务
Awesome!Alibaba interview reference guide (Songshan version) open source sharing, programmer interview must brush
Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法
Mysql 基本操作指南之mysql查询语句
80篇国产数据库实操文档汇总(含TiDB、达梦、openGauss等)
基于flask商城的管理员功能
Large and comprehensive pom file example
SQL函数 TRUNCATE
方正璞华“劳动人事法律自助咨询服务平台”在武汉武昌区投入使用!
els strip collision deformation judgment
基于华为eNSP的企业网络规划