当前位置:网站首页>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 了 .
边栏推荐
- GBase 8c 触发器(一)
- [shutter] pull the navigation bar sideways (drawer component | pageview component)
- Return a tree structure data
- 机器学习流程与方法
- require. context
- Face recognition 6-face_ recognition_ Py based on OpenCV, face detection and real-time tracking using Haar cascade and Dlib Library
- COM and cn
- Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- Deep learning notes (constantly updating...)
猜你喜欢

Solution for processing overtime orders (Overtime unpaid)

MySQL learning 03

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

8 free, HD, copyright free video material download websites are recommended

详细些介绍如何通过MQTT协议和华为云物联网进行通信

What are MySQL locks and classifications

What are the key points often asked in the redis interview

Restcloud ETL cross database data aggregation operation

How to deal with cache hot key in redis

返回一个树形结构数据
随机推荐
Producer consumer model based on thread pool (including blocking queue)
Job object of collaboration in kotlin
My creation anniversary
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
Exception handling in kotlin process
udp接收队列以及多次初始化的测试
Summary of ES6 filter() array filtering methods
PyTorch 卷积网络正则化 DropBlock
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
Awk from introduction to earth (0) overview of awk
Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
内存池(内核角度理解new开辟空间的过程)
How to deal with cache hot key in redis
Groovy, "try with resources" construction alternative
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
easyPOI
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
es6 filter() 数组过滤方法总结
awk从入门到入土(3)awk内置函数printf和print实现格式化打印