当前位置:网站首页>js 语言 精度问题
js 语言 精度问题
2022-06-23 22:20:00 【雷鸣_IT】
例如:
0.1+0.2 !== 0.3
0.1+0.3 === 0.4
0.1+0.4 === 0.5解决精度问题:
1,规定一定范围内 数据的误差允许则等价于相等
export const EPSILON = 0.000001;
/*
* EPSILON(小于等于1.0的值采用绝对公差,大于1.0的值采用相对公差)
* @param a The first number to test.
* @param b The second number to test.
* @return True if the numbers are approximately equal, false otherwise.
*/
export function equals (a: number, b: number) {
return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
}2,使用字符串进行比对
参考资料:
https://www.iteye.com/blog/thihy-1867577
边栏推荐
- EasyCVR程序以服务启动异常,进程启动却正常,是什么原因?
- .NET 中的 Worker Service 介绍
- Gbase observation: extended analytical database
- [things about gbase] gbase 8s high availability technology and case analysis (issue 02)
- 医疗是什么?AI医疗概念解析AI
- How to ensure reliable power supply of Expressway
- Batch renaming of images by MATLAB
- GBASE观察:扩展分析型数据库
- matlab实现对图像批量重命名
- 如何利用数仓创建时序表
猜你喜欢

Notepad++ practical function sharing (common methods for replacing the end and beginning of regular lines, text comparison function, etc.)

产线工控安全有什么好的解决方案

1.< tag-动态规划和路径组合问题>lt.62. 不同路径 + lt.63. 不同路径 II

Windows10 security mode entry cycle blue screen repair

逆向工具IDA、GDB使用

点乘和叉乘

Save: software analysis, verification and test platform

How to achieve energy-saving and reasonable lighting control in order to achieve the "double carbon" goal
![[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)](/img/e7/d36750c729b76f18418589356706f1.png)
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)

What is medical treatment? AI medical concept analysis AI
随机推荐
人工智能技术岗位面试要注意什么?
逆向工具IDA、GDB使用
Revit API:明细表 ViewSchedule
Recommend 4 flutter heavy open source projects
产线工控安全有什么好的解决方案
依赖倒置原则
Expander+listbox of WPF effect
CPU取指到发出控制、微程序控制原理详细过程
跟着CTF-wiki学pwn——ret2text
==What is the difference between and equals?
Six necessary open source projects for private activities
[technical grass planting] Tencent Yunhao wool (consumption) record on the double 11
Cvpr2019/ image translation: transgaga: geometry aware unsupervised image to image translation
Unity text component space newline problem
.NET 中的 Worker Service 介绍
docker redis集群配置
解决项目依赖报红问题
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
How to use data warehouse to create time series
Chrome plug-in features and case analysis of actual combat scenarios