WA and using while loop :P

Getting WA in a binary search problem using while loop and got AC using for loop…why it behaves so?please help…Thanks in advance :slight_smile:

Problem : Online Judge

Code : /******************************** Bismillahir Rahmanir Rahim* Harunur Rash - Pastebin.com

My guess:
f(x)<0, f(y)>=0 and |x-y|<eps does not imply |f(x)|<eps - think about functions woth a big slope.

So your test possibly prints no solution even if you have actually found one.

With the for loop you are determining x with a precision of 2^{-50} (or machine precision, whichever is bigger), smaller than the 10-9 of the while loop. In this case |x-y|\leq 2^{-50} seems to be small enough to imply |f(x)|<eps for the testcases

1 Like

thanks @ceilks :slight_smile: