问题描述
我知道比较两个真实是不可能的,但是对于具有2的分母幂的真实是真的吗?这个王的平等总是返回真
这种表达式应该始终评估为 true ,有一些注意事项:
- 分子不超过2 ^ 52;否则会失去精度。
- 分母不会超出双精度提供的范围。
- 您必须在平台上工作使用基数为2的浮点数(基本上所有现代机器)。
I know it's not "possible" to compare two real, but is it true for real which have denominator power of 2
Is equality of this king always return true
if( 3/4. == 6/8. ) {}解决方案This kind of expression should always evaluate to true, with a few caveats:
- The numerators don't exceed 2^52; otherwise they'll lose precision.
- The denominators don't exceed the range provided by double-precision.
- You must be working on a platform that uses radix-2 floating-point (which is basically all modern machines).
这篇关于我可以比较两个分数,如果两个分母的幂为2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!