浮点数==和!=的全局重载 [英] Global overloading of == and != for floating-points

查看:102
本文介绍了浮点数==和!=的全局重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重载全局运算符==!=的浮点值是不好的做法吗?我在游戏环境中使用快速浮点,并且我正在考虑在所有地方使用模糊比较,因为我无法想象这样的情况,即我不希望极端接近的数字不相等.

Is it a bad practice to overload global operator == and != for floating points ? I'm using fast floating-points in a game environement, and i was thinking about using fuzzy comparison everywhere as i can't imagine a situation where i don't expect extremely close numbers not to be equals.

有什么建议吗?

推荐答案

其他帖子从另一个角度提到了技术问题:

Other posts mentioned technical problems, from another perspective:

这是一个坏习惯,因为没有人期望这些运算符会重载,而有理智的人会期望使用almostEquals函数.它的奇怪和奇怪,掩盖了真正发生的事情.

Its a bad practice because nobody expects these operators to be overloaded, while reasonable people will expect an almostEquals function. Its strange and odd and masks what is really going on.

这篇关于浮点数==和!=的全局重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆