当前位置:网站首页>浮点数如何与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
边栏推荐
- Gin integrated Alipay payment
- [differential privacy and data adaptability] differential privacy code implementation series (XIV)
- Details of FPGA underlying resources
- Comment configurer un accord
- Partial modification - progressive development
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
- 如何搭建一支搞垮公司的技术团队?
- Techsmith Camtasia Studio 2022.0.2屏幕录制软件
- Red envelope activity design in e-commerce system
- leetcode:6109. Number of people who know the secret [definition of DP]
猜你喜欢
Redis 發布和訂閱
The performance of major mainstream programming languages is PK, and the results are unexpected
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
LVGL 8.2 Line
[C language] Pointer written test questions
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
Preliminary exploration of flask: WSGI
5G电视难成竞争优势,视频资源成中国广电最后武器
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
LVGL 8.2 LED
随机推荐
Ranking list of databases in July: mongodb and Oracle scores fell the most
openresty 限流
Redis 发布和订阅
Ali was laid off employees, looking for a job n day, headhunters came bad news
C language set operation
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
现代控制理论入门+理解
Explain of SQL optimization
[algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
03 storage system
Openresty current limiting
为什么国产手机用户换下一部手机时,都选择了iPhone?
Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
5G电视难成竞争优势,视频资源成中国广电最后武器
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
Count the running time of PHP program and set the maximum running time of PHP
Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
Introduction to modern control theory + understanding
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)