Qt浮点数比较qFuzzyIsNull

来源:互联网 发布:淘宝七天上下架规则 编辑:程序博客网 时间:2024/06/06 12:33

在qt中有对于浮点数比较函数qFuzzyIsNull,其实现代码也相对简单

static inline bool qFuzzyIsNull(float f)

{
    return qAbs(f) <= 0.00001f;
}
其中一般使用是将两个浮点数相减,其中底层大量使用,如QPointF的比较操作
inline bool operator==(const QPointF &p1, const QPointF &p2)
{
    return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
}
原创粉丝点击