当前位置:网站首页>About binary cannot express decimals accurately
About binary cannot express decimals accurately
2022-07-07 07:14:00 【Crystal heart spring】
In a previous project, I encountered the problem of inaccurate decimal calculation , As shown in the figure below
I reproduced it , Is roughly 1.05+1+1.05// 3.0999999999999996
Such , So I looked at how binary represents decimal .
To put it simply , That is, we can understand binary floating-point numbers by analogy with decimal floating-point numbers
Decimal system | 1 | 2 | 3 | . | 5 | 8 | 9 |
Way of understanding | 1*102 | 2*101 | 3*100 | . | 5*(1/101) | 8*(1/102) | 9*(1/10%3) |
Binary system | 1 | 1 | 1 | . | 1 | 0 | 1 |
Way of understanding | 1*22 | 1*21 | 1*20 | . | 1*(1/21) | 1*(1/22) | 1*(1/23) |
Therefore, binary can only accurately represent 0.5(1/2)
、0.25(1/4)
、0.125(1/8)
、0.0625(1/16)
、… This kind of decimal , Of course, like 1.0
、2.0
、3.0
This kind of decimal part is all 0
Of can also be accurately expressed , Other decimals cannot be expressed accurately , Therefore, the operation result may have a long tail , The reason why some of them will not have long tails , After referring to other materials, we can find that the language itself has been partially optimized , Too close numbers will be directly optimized into seemingly accurate values by language .
Decimal number | Binary system |
---|---|
0.1 | 0.0001100110011001100110011001100110011001100110011001101 |
0.2 | 0.001100110011001100110011001100110011001100110011001101 |
0.3 | 0.010011001100110011001100110011001100110011001100110011 |
0.4 | 0.01100110011001100110011001100110011001100110011001101 |
0.5 | 0.1 |
0.6 | 0.10011001100110011001100110011001100110011001100110011 |
0.7 | 0.1011001100110011001100110011001100110011001100110011 |
0.8 | 0.1100110011001100110011001100110011001100110011001101 |
0.9 | 0.11100110011001100110011001100110011001100110011001101 |
0.10 | 0.0001100110011001100110011001100110011001100110011001101 |
0.11 | 0.00011100001010001111010111000010100011110101110000101001 |
0.12 | 0.00011110101110000101000111101011100001010001111010111 |
0.13 | 0.00100001010001111010111000010100011110101110000101001 |
0.14 | 0.00100011110101110000101000111101011100001010001111011 |
0.15 | 0.0010011001100110011001100110011001100110011001100110011 |
0.16 | 0.0010100011110101110000101000111101011100001010001111011 |
0.17 | 0.0010101110000101000111101011100001010001111010111000011 |
0.18 | 0.001011100001010001111010111000010100011110101110000101 |
0.19 | 0.001100001010001111010111000010100011110101110000101001 |
0.20 | 0.001100110011001100110011001100110011001100110011001101 |
0.21 | 0.0011010111000010100011110101110000101000111101011100001 |
0.22 | 0.0011100001010001111010111000010100011110101110000101001 |
0.23 | 0.0011101011100001010001111010111000010100011110101110001 |
0.24 | 0.0011110101110000101000111101011100001010001111010111 |
0.25 | 0.01 |
0.26 | 0.0100001010001111010111000010100011110101110000101001 |
0.27 | 0.010001010001111010111000010100011110101110000101001 |
0.28 | 0.0100011110101110000101000111101011100001010001111011 |
0.29 | 0.010010100011110101110000101000111101011100001010001111 |
0.30 | 0.010011001100110011001100110011001100110011001100110011 |
0.31 | 0.010011110101110000101000111101011100001010001111010111 |
0.32 | 0.010100011110101110000101000111101011100001010001111011 |
0.33 | 0.010101000111101011100001010001111010111000010100011111 |
0.34 | 0.010101110000101000111101011100001010001111010111000011 |
0.35 | 0.01011001100110011001100110011001100110011001100110011 |
0.36 | 0.01011100001010001111010111000010100011110101110000101 |
0.37 | 0.01011110101110000101000111101011100001010001111010111 |
0.38 | 0.01100001010001111010111000010100011110101110000101001 |
0.39 | 0.01100011110101110000101000111101011100001010001111011 |
0.40 | 0.01100110011001100110011001100110011001100110011001101 |
0.41 | 0.011010001111010111000010100011110101110000101000111101 |
0.42 | 0.011010111000010100011110101110000101000111101011100001 |
0.43 | 0.011011100001010001111010111000010100011110101110000101 |
0.44 | 0.011100001010001111010111000010100011110101110000101001 |
0.45 | 0.011100110011001100110011001100110011001100110011001101 |
0.46 | 0.011101011100001010001111010111000010100011110101110001 |
0.47 | 0.0111100001010001111010111000010100011110101110000101 |
0.48 | 0.011110101110000101000111101011100001010001111010111 |
0.49 | 0.0111110101110000101000111101011100001010001111010111 |
0.50 | 0.1 |
0.51 | 0.1000001010001111010111000010100011110101110000101001 |
0.52 | 0.100001010001111010111000010100011110101110000101001 |
0.53 | 0.1000011110101110000101000111101011100001010001111011 |
0.54 | 0.10001010001111010111000010100011110101110000101001 |
0.55 | 0.1000110011001100110011001100110011001100110011001101 |
0.56 | 0.100011110101110000101000111101011100001010001111011 |
0.57 | 0.10010001111010111000010100011110101110000101000111101 |
0.58 | 0.10010100011110101110000101000111101011100001010001111 |
0.59 | 0.10010111000010100011110101110000101000111101011100001 |
0.60 | 0.10011001100110011001100110011001100110011001100110011 |
0.61 | 0.10011100001010001111010111000010100011110101110000101 |
0.62 | 0.10011110101110000101000111101011100001010001111010111 |
0.63 | 0.10100001010001111010111000010100011110101110000101001 |
0.64 | 0.10100011110101110000101000111101011100001010001111011 |
0.65 | 0.10100110011001100110011001100110011001100110011001101 |
0.66 | 0.10101000111101011100001010001111010111000010100011111 |
0.67 | 0.10101011100001010001111010111000010100011110101110001 |
0.68 | 0.10101110000101000111101011100001010001111010111000011 |
0.69 | 0.101100001010001111010111000010100011110101110000101 |
0.70 | 0.1011001100110011001100110011001100110011001100110011 |
0.71 | 0.10110101110000101000111101011100001010001111010111 |
0.72 | 0.1011100001010001111010111000010100011110101110000101 |
0.73 | 0.101110101110000101000111101011100001010001111010111 |
0.74 | 0.1011110101110000101000111101011100001010001111010111 |
0.75 | 0.11 |
0.76 | 0.1100001010001111010111000010100011110101110000101001 |
0.77 | 0.110001010001111010111000010100011110101110000101001 |
0.78 | 0.1100011110101110000101000111101011100001010001111011 |
0.79 | 0.11001010001111010111000010100011110101110000101001 |
0.80 | 0.1100110011001100110011001100110011001100110011001101 |
0.81 | 0.110011110101110000101000111101011100001010001111011 |
0.82 | 0.11010001111010111000010100011110101110000101000111101 |
0.83 | 0.11010100011110101110000101000111101011100001010001111 |
0.84 | 0.11010111000010100011110101110000101000111101011100001 |
0.85 | 0.11011001100110011001100110011001100110011001100110011 |
0.86 | 0.11011100001010001111010111000010100011110101110000101 |
0.87 | 0.11011110101110000101000111101011100001010001111010111 |
0.88 | 0.11100001010001111010111000010100011110101110000101001 |
0.89 | 0.11100011110101110000101000111101011100001010001111011 |
0.90 | 0.11100110011001100110011001100110011001100110011001101 |
0.91 | 0.11101000111101011100001010001111010111000010100011111 |
0.92 | 0.11101011100001010001111010111000010100011110101110001 |
0.93 | 0.11101110000101000111101011100001010001111010111000011 |
0.94 | 0.111100001010001111010111000010100011110101110000101 |
0.95 | 0.1111001100110011001100110011001100110011001100110011 |
0.96 | 0.11110101110000101000111101011100001010001111010111 |
0.97 | 0.1111100001010001111010111000010100011110101110000101 |
0.98 | 0.111110101110000101000111101011100001010001111010111 |
0.99 | 0.1111110101110000101000111101011100001010001111010111 |
边栏推荐
- Détailler le bleu dans les tâches de traduction automatique
- Implementation of AVL tree
- Basic introduction of JWT
- Four goals for the construction of intelligent safety risk management and control platform for hazardous chemical enterprises in Chemical Industry Park
- SQLMAP使用教程(四)实战技巧三之绕过防火墙
- Exception of DB2 getting table information: caused by: com ibm. db2.jcc. am. SqlException: [jcc][t4][1065][12306][4.25.13]
- Paranoid unqualified company
- Config distributed configuration center
- 2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书第二阶段答案
- Mysql---- import and export & View & Index & execution plan
猜你喜欢
$refs:组件中获取元素对象或者子组件实例:
The latest trends of data asset management and data security at home and abroad
2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书第二阶段答案
freeswitch拨打分机号源代码跟踪
Abnova circulating tumor DNA whole blood isolation, genomic DNA extraction and analysis
. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context
Jetpack compose is much more than a UI framework~
AVL树的实现
Composition API 前提
Config分布式配置中心
随机推荐
Four goals for the construction of intelligent safety risk management and control platform for hazardous chemical enterprises in Chemical Industry Park
LC 面试题 02.07. 链表相交 & LC142. 环形链表II
PostgreSQL source code (59) analysis of transaction ID allocation and overflow judgment methods
父组件传递给子组件:Props
Brand · consultation standardization
Introduction to abnova's in vitro mRNA transcription workflow and capping method
组件的嵌套和拆分
LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
Multithreading and high concurrency (9) -- other synchronization components of AQS (semaphore, reentrantreadwritelock, exchanger)
Exception of DB2 getting table information: caused by: com ibm. db2.jcc. am. SqlException: [jcc][t4][1065][12306][4.25.13]
Libcurl returns curlcode description
PostgreSQL source code (60) transaction system summary
. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context
How can clothing stores make profits?
2018 Jiangsu Vocational College skills competition vocational group "information security management and evaluation" competition assignment
freeswitch拨打分机号源代码跟踪
OOM(内存溢出)造成原因及解决方案
Bus消息总线
Bindingexception exception (error reporting) processing
Abnova immunohistochemical service solution