#include <iostream>
using std::cout;
int main()
{
double a = 9.0;
cout << (1.0*a/a == 1.0) << " " << (1.0/a*a == 1.0) << std::endl;
}
Comes out as "1 1" using a modern compiler (https://ideone.com/obfDkH ). I thing I'd expect a decent, modern compiler running under normal circumstances to spot those cancelling values and just not bother with them.
re Moschops:
sorry another mistake. i'm using code::blocks.
it outputs 1 1 too if a = 9.0
however, it gives 1 0 if a = 99.0
(for a = 98 or 14, etc. it gives 1 1)
re Chervil:
wow, i think it's very important to know this concept.
if a = 99.0
compiler reads from left to right so (1.0/a*a) won't give 1 (because of the decimal point the compiler will store?)
however, compiler gives a true if a = 9.0
is it about my compiler? or i have misunderstood your explanation?
code::blocks isn't a compiler. It's an IDE. code::blocks can be used with many different compilers. That's something for you to learn; what a compiler is, how they're used, and what compiler you are using.