当前位置:网站首页>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
边栏推荐
- Numpy notes
- PXE网络
- 深入JS中几种数据类型的解构赋值细节
- Unity update process_ Principle of unity synergy
- 【读书会第十三期】 音频文件的封装格式和编码格式
- MySQL index optimization
- Dry goods | fMRI standard reporting guidelines are fresh, come and increase your knowledge
- [book club issue 13] ffmpeg common methods for viewing media information and processing audio and video files
- 压力、焦虑还是抑郁? 正确诊断再治疗
- What encryption algorithm is used for the master password of odoo database?
猜你喜欢

科研漫画 | 联系到被试后还需要做什么?
MySQL组合索引(多列索引)使用与优化案例详解

MySQL index optimization

Neuf tendances et priorités du DPI en 2022

Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
Redis的4种缓存模式分享

Lombok使用引发的血案
Detailed explanation of MySQL composite index (multi column index) use and optimization cases

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

这几年爆火的智能物联网(AIoT),到底前景如何?
随机推荐
unity update 协程_Unity 协程的原理
深入JS中几种数据类型的解构赋值细节
js平铺数据查找叶子节点
Unity脚本API—Transform 变换
這幾年爆火的智能物聯網(AIoT),到底前景如何?
Decimal, exponential
c# 实现定义一套中间SQL可以跨库执行的SQL语句
Implementation of web chat room
Unity动画Animation Day05
They are all talking about Devops. Do you really understand it?
Unity script lifecycle day02
MySQL~MySQL给已有的数据表添加自增ID
2022年九大CIO趋势和优先事项
31年前的Beyond演唱会,是如何超清修复的?
MP3是如何诞生的?
Weibo and Huya advance into interest communities: different paths for peers
Data Lake Governance: advantages, challenges and entry
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?
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
从0到1建设智能灰度数据体系:以vivo游戏中心为例