当前位置:网站首页>浮点数如何与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
边栏推荐
- LVLG 8.2 circular scrolling animation of a label
- 炒股网上开户安全吗?会不会被骗。
- Leecode learning notes - Joseph problem
- 《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
- 内存管理总结
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
- LVGL 8.2 Draw label with gradient color
- Graduation season - personal summary
- (1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
- Digi restarts XBee Pro S2C production. Some differences need to be noted
猜你喜欢
LVGL 8.2 text shadow
Summary of common problems in development
Ranking list of databases in July: mongodb and Oracle scores fell the most
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
都在说DevOps,你真正了解它吗?
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
各大主流编程语言性能PK,结果出乎意料
Redis 发布和订阅
Explain of SQL optimization
随机推荐
程序员自曝接私活:10个月时间接了30多个单子,纯收入40万
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
IO流:节点流和处理流详细归纳。
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
Halo effect - who says that those with light on their heads are heroes
ES6 modularization
Kubernets pod exists finalizers are always in terminating state
Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
Introduction to modern control theory + understanding
局部修改-渐进型开发
On the implementation plan of MySQL explain
LVGL 8.2 Menu
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
Respect others' behavior
深度学习 神经网络的优化方法
Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
Query optimizer for SQL optimization
5G电视难成竞争优势,视频资源成中国广电最后武器
Flutter reports an error no mediaquery widget ancestor found