当前位置:网站首页>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脚本API—Time类
- [book club issue 13] coding format of video files
- Redis的4种缓存模式分享
- TechSmith Camtasia studio 2022.0.2 screen recording software
- . Net applications consider x64 generation
- 找数字
- 【读书会第十三期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
- Optimization method of deep learning neural network
- Numpy notes
- An article learns variables in go language
猜你喜欢
How did the beyond concert 31 years ago get super clean and repaired?
Redis 發布和訂閱
Redis publish and subscribe
lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
They are all talking about Devops. Do you really understand it?
Unity脚本常用API Day03
這幾年爆火的智能物聯網(AIoT),到底前景如何?
MySQL组合索引(多列索引)使用与优化案例详解
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
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
随机推荐
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
函数式接口,方法引用,Lambda实现的List集合排序小工具
【读书会第十三期】 音频文件的封装格式和编码格式
Blood cases caused by Lombok use
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
Huawei cloud database DDS products are deeply enabled
重排数组
web聊天室实现
Neuf tendances et priorités du DPI en 2022
Unity动画Animation Day05
MySQL学习笔记——数据类型(数值类型)
The per capita savings of major cities in China have been released. Have you reached the standard?
浮点数如何与0进行比较?
AI做题水平已超过CS博士?
They are all talking about Devops. Do you really understand it?
C1 certification learning notes 3 -- Web Foundation
一篇文章学会GO语言中的变量
小数,指数
Scientific research cartoon | what else to do after connecting with the subjects?
Common API day03 of unity script