当前位置:网站首页>浮点数如何与0进行比较?
浮点数如何与0进行比较?
2022-07-04 13:31:00 【北冥有鱼丶丶】
浮点数类型的变量与0的比较我们通常采取下面这种方式
//先定义一个值极小的宏
#define ESP 0.00000000000000001
//1.判断是否等于0
//然后将浮点数与0.0差值的绝对值与该极小值进行比较
//如果浮点数与0.0差值的绝对值小于该极小值,那么我们就认为浮点数等于0.0
float a = 0.0f;
scanf("%f",&a);
if(fabs(a - 0.0) < ESP)
{
//那么fabs(a - 0.0) == 0
//即a - 0.0的绝对值为0
//即a = 0.0
}
//2.判断是否大于0
if(a >= ESP)
//那么a大于0
边栏推荐
- LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
- Ali was laid off employees, looking for a job n day, headhunters came bad news
- Expose Ali's salary and position level
- 现代控制理论入门+理解
- Deep learning 7 transformer series instance segmentation mask2former
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
- Practical puzzle solving | how to extract irregular ROI regions in opencv
- Ranking list of databases in July: mongodb and Oracle scores fell the most
- Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
- Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
猜你喜欢

Transplant tinyplay for imx6q development board QT system

Practical puzzle solving | how to extract irregular ROI regions in opencv

Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)

智能客服赛道:网易七鱼、微洱科技打法迥异

程序员自曝接私活:10个月时间接了30多个单子,纯收入40万

Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022

自动控制原理快速入门+理解

Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)

Summary of common problems in development

UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
随机推荐
Chapter 16 string localization and message Dictionary (2)
EventBridge 在 SaaS 企业集成领域的探索与实践
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
Respect others' behavior
智能客服赛道:网易七鱼、微洱科技打法迥异
内存管理总结
[C language] Pointer written test questions
Gin integrated Alipay payment
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
Node mongodb installation
LVLG 8.2 circular scrolling animation of a label
Programmer turns direction
Codeforce:c. sum of substrings
Why do domestic mobile phone users choose iPhone when changing a mobile phone?
为什么国产手机用户换下一部手机时,都选择了iPhone?
Combined with case: the usage of the lowest API (processfunction) in Flink framework
对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
LVGL 8.2 keyboard
Query optimizer for SQL optimization