Hey there, I was solving 789B and I had this very simple and short code but it just fails on test 3 although it works perfectly on my machine. I have read that undefined behavior can induce this but I can't recognize what's wrong with what I typed. Here's the code:
Thank you!!
I've added outputting an empty string before the
if
and got AC. I don't know why it works.code
You compare doubles using ==. Don't do that.
In general, yes, you're right. But why do r1 and r2 differ in this case (for the input data
6 6
)?If x is 6 and y is 6, then surely
r1 == r2
is true:Why adding
cout<<"";
changes the result of the test (see my comment above)?In short, r1 == r2 is true if they are both 64bit floats, compiler may calculate and store one of them in 80bit register (for optimization), and 80bit logarithm != 64bit logarithm. And cout disables this optimization.
This issue was discussed here (and not here) million times, but every time there is a person who didn't read these discussions.
Actually, not. Even for the following example:
[Deleted] Wrong Info