当前位置:网站首页>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
边栏推荐
猜你喜欢

每周招聘|高级DBA年薪49+,机会越多,成功越近!

从0到1建设智能灰度数据体系:以vivo游戏中心为例

Lombok使用引发的血案

干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧

Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?

LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04

MYSQL索引优化

Redis 解决事务冲突之乐观锁和悲观锁
Redis的4种缓存模式分享

Unity动画Animation Day05
随机推荐
Go deep into the details of deconstruction and assignment of several data types in JS
Introduction of text mining tools [easy to understand]
Common API day03 of unity script
开源人张亮的 17 年成长路线,热爱才能坚持
Redis哨兵模式实现一主二从三哨兵
文本挖掘工具的介绍[通俗易懂]
Logstash ~ detailed explanation of logstash configuration (logstash.yml)
How to rapidly deploy application software under SaaS
左右对齐!
Data Lake Governance: advantages, challenges and entry
Analysis of nearly 100 million dollars stolen and horizon cross chain bridge attacked
MySQL~MySQL给已有的数据表添加自增ID
web聊天室实现
Shell programming basics
Case sharing | integrated construction of data operation and maintenance in the financial industry
Weibo and Huya advance into interest communities: different paths for peers
c# 实现定义一套中间SQL可以跨库执行的SQL语句
深入JS中几种数据类型的解构赋值细节
函数式接口,方法引用,Lambda实现的List集合排序小工具
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance