当前位置:网站首页>Javescript 0.1 + 0.2 = = 0.3 problem
Javescript 0.1 + 0.2 = = 0.3 problem
2022-07-03 02:21:00 【weixin_ forty-nine million thirty-five thousand four hundred an】
According to the definition of double precision floating point number ,Number The valid integer range in type is -0x1fffffffffffff to 0x1fffffffffffff, therefore Number Can't represent integers outside this range exactly .
Again, according to the definition of floating point numbers , Non integer Number Type unavailable ==(=== Not good either. ) To compare , A famous piece of code , This is also the problem of our third question , Why is it JavaScript in ,0.1+0.2 You can't =0.3:
console.log( 0.1 + 0.2 == 0.3);
The output here is false, Explain that the two sides are not equal , This is the characteristic of floating point operation , It is also the source of many students' doubts , The precision problem of floating-point operation leads to that the left and right results of the equation are not strictly equal , It's a tiny difference .
So actually , The wrong conclusion here is not , It's a method of comparison , The right way to compare is to use JavaScript The minimum accuracy value provided :
console.log( Math.abs(0.1 + 0.2 - 0.3) <= Number.EPSILON);
Check whether the absolute value of the difference between the left and right sides of the equation is less than the minimum accuracy , Is the right way to compare floating-point numbers . The result of this code is true 了 .
边栏推荐
- easyPOI
- The sandbox explains its vision for the meta universe platform
- 【教程】chrome关闭跨域策略cors、samesite,跨域带上cookie
- GBase 8c系统表pg_database
- Cfdiv2 Fixed Point Guessing - (2 points for Interval answer)
- 通达OA 首页门户工作台
- Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
- Swift development learning
- 机器学习流程与方法
- awk从入门到入土(2)认识awk内置变量和变量的使用
猜你喜欢

Use go language to realize try{}catch{}finally

《上市风云》荐书——唯勇气最可贵

oauth2.0鉴权,登录访问 “/oauth/token”,请求头Authorization(basicToken)如何取值???

Return a tree structure data

Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)

stm32F407-------DMA

创建+注册 子应用_定义路由,全局路由与子路由
![[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)](/img/66/0fda43da0d36fc0c9277ca86ece252.jpg)
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)

Deep learning notes (constantly updating...)

线程安全的单例模式
随机推荐
Machine learning process and method
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
COM and cn
Exception handling in kotlin process
8 free, HD, copyright free video material download websites are recommended
PyTorch 卷积网络正则化 DropBlock
Visual yolov5 format data set (labelme JSON file)
502 (bad gateway) causes and Solutions
5. File operation
Awk from getting started to getting into the ground (3) the built-in functions printf and print of awk realize formatted printing
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
Su Shimin: 25 principles of work and life
深度学习笔记(持续更新中。。。)
How can retail enterprises open the second growth curve under the full link digital transformation
SPI mechanism
Startup mode and scope builder of collaboration in kotlin
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
Missing library while loading shared libraries: libisl so. 15: cannot open shared object file: No such file
Current situation and future of Web3 in various countries
Socket programming