当前位置:网站首页>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
边栏推荐
- Unity脚本生命周期 Day02
- LeetCode 1184. 公交站间的距离 ---vector顺逆时针
- 文本挖掘工具的介绍[通俗易懂]
- %f格式符
- Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
- C implementation defines a set of intermediate SQL statements that can be executed across libraries
- Go deep into the details of deconstruction and assignment of several data types in JS
- 31年前的Beyond演唱会,是如何超清修复的?
- 這幾年爆火的智能物聯網(AIoT),到底前景如何?
- 宽度精度
猜你喜欢
Deep learning neural network case (handwritten digit recognition)
华为云数据库DDS产品深度赋能
Weibo and Huya advance into interest communities: different paths for peers
Preliminary exploration of flask: WSGI
.Net 应用考虑x64生成
Nine CIO trends and priorities in 2022
Helix swarm Chinese package is released, and perforce further improves the user experience in China
MySQL index optimization
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
随机推荐
The per capita savings of major cities in China have been released. Have you reached the standard?
Deep learning neural network case (handwritten digit recognition)
数据湖治理:优势、挑战和入门
Lombok使用引发的血案
Width and alignment
中国主要城市人均存款出炉,你达标了吗?
An article learns variables in go language
selenium 元素交互
Neuf tendances et priorités du DPI en 2022
MySQL组合索引(多列索引)使用与优化案例详解
c# 实现定义一套中间SQL可以跨库执行的SQL语句
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
一篇文章搞懂Go语言中的Context
Huawei cloud database DDS products are deeply enabled
Redis publier et s'abonner
怎么判断外盘期货平台正规,资金安全?
Logstash ~ detailed explanation of logstash configuration (logstash.yml)
Weibo and Huya advance into interest communities: different paths for peers
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
C1 certification learning notes 3 -- Web Foundation