Different return values

I have a function returning 8 for double return type and 7 for long return type. Am not posting the function since its someway related to the ongoing contest. Can anyone pls tell me why it happens so?
Its like

double f(){return y;}
long x=f();
cout<<x<<" "<<f();

O/P is like 7 8

Did I understood you well, when you change double f(){return y;} to long f(){return y;} it returns 8 instead of 7 ?

Its the otherway!

It is due to precision issues as the inbuilt function is rounding up the value of some test cases and rounding down the others, i wasted like 3 days on the same thing.

1 Like

And you found a way to get it right?

Yeah with some extra conditions on the return value, to check if its correct or not.

Well… Thanks!

I think your question and comments are leaking TOO much information during the competition. Thousands of people here are still facing the same issue. Please wait till Monday.

you should use printf() and set precision to be .20f then you can see that the true value was 7.99999999xxxx something like this. but because you are not printing double output to that pecision it is getting rounded up to 8. but long still will take integral part part of that so it is giving 7 still. I hope this would help.

1 Like
//