我可以比较两个分数,如果两个分母的幂为2 [英] can I compare two fractions if both have denominator with power of 2

查看:132
本文介绍了我可以比较两个分数,如果两个分母的幂为2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道比较两个真实是不可能的,但是对于具有2的分母幂的真实是真的吗?这个王的平等总是返回真

  if(3/4。== 6/8。){} 


解决方案

这种表达式应该始终评估为 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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