当前位置:网站首页>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
边栏推荐
- How to rapidly deploy application software under SaaS
- [book club issue 13] packaging format and coding format of audio files
- LeetCode 35. 搜索插入位置 —vector遍历(O(logn)和O(n)的写法---二分查找法)
- Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
- LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
- selenium 元素交互
- Redis publier et s'abonner
- Detailed explanation of MySQL composite index (multi column index) use and optimization cases
- Flutter reports an error no mediaquery widget ancestor found
- 十六进制
猜你喜欢

力扣刷题01(反转链表+滑动窗口+LRU缓存机制)

MySQL learning notes - data type (numeric type)

Deep learning neural network case (handwritten digit recognition)

.Net 应用考虑x64生成

Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!

科研漫画 | 联系到被试后还需要做什么?

Lombok使用引发的血案

Summer Review, we must avoid stepping on these holes!

【大连理工大学】考研初试复试资料分享

Redis publish and subscribe
随机推荐
. Net applications consider x64 generation
AI做题水平已超过CS博士?
Unity script API - transform transform
Functional interface, method reference, list collection sorting gadget implemented by lambda
MySQL~MySQL给已有的数据表添加自增ID
Decimal, exponential
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
%s格式符
MySQL学习笔记——数据类型(数值类型)
C1 certification learning notes 3 -- Web Foundation
函数式接口,方法引用,Lambda实现的List集合排序小工具
在芯片高度集成的今天,绝大多数都是CMOS器件
Go deep into the details of deconstruction and assignment of several data types in JS
这几年爆火的智能物联网(AIoT),到底前景如何?
2022年九大CIO趨勢和優先事項
Common API day03 of unity script
Helix swarm Chinese package is released, and perforce further improves the user experience in China
Detailed explanation of MySQL composite index (multi column index) use and optimization cases
[book club issue 13] packaging format and coding format of audio files
【大连理工大学】考研初试复试资料分享