当前位置:网站首页>How can floating point numbers be compared with 0?
How can floating point numbers be compared with 0?
2022-07-04 15:36:00 【There are fish in Beiming】
Floating point type variables and 0 We usually take the following way to compare
// First define a macro with a minimum value
#define ESP 0.00000000000000001
//1. Judge whether it is equal to 0
// Then compare the floating-point number with 0.0 The absolute value of the difference is compared with the minimum
// If floating-point numbers and 0.0 The absolute value of the difference is less than the minimum , Then we think floating point numbers are equal to 0.0
float a = 0.0f;
scanf("%f",&a);
if(fabs(a - 0.0) < ESP)
{
// that fabs(a - 0.0) == 0
// namely a - 0.0 The absolute value of is 0
// namely a = 0.0
}
//2. Judge whether it is greater than 0
if(a >= ESP)
// that a Greater than 0
边栏推荐
- PXE网络
- Unity脚本生命周期 Day02
- Logstash~Logstash配置(logstash.yml)详解
- Weibo and Huya advance into interest communities: different paths for peers
- %s格式符
- LeetCode 35. Search the insertion position - vector traversal (O (logn) and O (n) - binary search)
- 這幾年爆火的智能物聯網(AIoT),到底前景如何?
- Temperature control system based on max31865
- Optimization method of deep learning neural network
- MYSQL索引优化
猜你喜欢
Dry goods | fMRI standard reporting guidelines are fresh, come and increase your knowledge
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
压力、焦虑还是抑郁? 正确诊断再治疗
MySQL学习笔记——数据类型(2)
Dialogue with ye Yanxiu, senior consultant of Longzhi and atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
Redis publier et s'abonner
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Redis 解决事务冲突之乐观锁和悲观锁
MYSQL索引优化
随机推荐
Lombok使用引发的血案
Unity prefab day04
LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
Redis publish and subscribe
一篇文章学会GO语言中的变量
CentOS 6.3 下 PHP编译安装JSON模块报错解决
The per capita savings of major cities in China have been released. Have you reached the standard?
Unity animation day05
PXE网络
go-zero微服务实战系列(九、极致优化秒杀性能)
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
selenium 浏览器(2)
How did the beyond concert 31 years ago get super clean and repaired?
LeetCode 35. 搜索插入位置 —vector遍历(O(logn)和O(n)的写法---二分查找法)
直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
An article learns variables in go language
数据湖治理:优势、挑战和入门
MP3是如何诞生的?
Unity脚本API—GameObject游戏对象、Object 对象