当前位置:网站首页>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
边栏推荐
- Solve the error of JSON module in PHP compilation and installation under CentOS 6.3
- web聊天室实现
- [book club issue 13] ffmpeg common methods for viewing media information and processing audio and video files
- Unity脚本生命周期 Day02
- Case sharing | integrated construction of data operation and maintenance in the financial industry
- I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
- 谈SaaS下如何迅速部署应用软件
- Summer Review, we must avoid stepping on these holes!
- JS tile data lookup leaf node
- LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
猜你喜欢

Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)

直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构

在芯片高度集成的今天,绝大多数都是CMOS器件
Redis的4种缓存模式分享

Deep learning network regularization

函数式接口,方法引用,Lambda实现的List集合排序小工具

MySQL learning notes - data type (numeric type)

They are all talking about Devops. Do you really understand it?

Analysis of nearly 100 million dollars stolen and horizon cross chain bridge attacked

这几年爆火的智能物联网(AIoT),到底前景如何?
随机推荐
LeetCode 58. Length of the last word
Logstash~Logstash配置(logstash.yml)详解
2022 financial products that can be invested
数据库函数的用法「建议收藏」
LeetCode 1184. Distance between bus stops -- vector clockwise and counterclockwise
Data Lake Governance: advantages, challenges and entry
MySQL learning notes - data type (numeric type)
What encryption algorithm is used for the master password of odoo database?
Unity脚本常用API Day03
unity update 协程_Unity 协程的原理
How to rapidly deploy application software under SaaS
Unity script API - time class
LeetCode 35. Search the insertion position - vector traversal (O (logn) and O (n) - binary search)
Preliminary exploration of flask: WSGI
Unity animation day05
Unity script API - GameObject game object, object object
C implementation defines a set of intermediate SQL statements that can be executed across libraries
Shell 编程基础
浮点数如何与0进行比较?
Scientific research cartoon | what else to do after connecting with the subjects?