I was just wondering why
cout << (1000 < 1000) << endl;
gives 0
, while
cout << (1000 < pow(10, 3)) << endl;
gives 1
.
I was just wondering why
cout << (1000 < 1000) << endl;
gives 0
, while
cout << (1000 < pow(10, 3)) << endl;
gives 1
.
std::pow
does not work on integral types. If you supply it integers, it will cast them to double
(see 7th overload on the linked page).
The result of the call is then a double
, which happens to be slightly biased up (as floating-point arithmetic is lossy), enough to compare strictly larger with a literal value of 1000
directly converted to double
.
See What Every Computer Scientist Should Know About Floating-Point Arithmetic.