Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I compare two fractions if both have denominator with power of 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. ) {}
like image 893
Guillaume Paris Avatar asked Feb 24 '23 23:02

Guillaume Paris


1 Answers

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).
like image 130
Oliver Charlesworth Avatar answered Apr 28 '23 04:04

Oliver Charlesworth