Why there is wrong output of ceil and floor values in this code :
enter code here
using namespace std;
typedef long long ll;
float y = 99999980;
float z =-99999980;
ll x = ceil(y);
ll q = floor(z);
can any one explain me why such thing is happening ?
Try these commands-
By default xxxx.xxx are treated as double in c/c++. when you save as float it is saved as 99999984.0
Due to small size of float. which often results in round off of floats.
Round off section. As 99999980.0 is large number it is saved as 99999984.0 when stored in float data type.
And hence the reason for wrong input.
This is also the reason why using == operations with floats/double is not considered as safe.
yes that should be the reason . even when i am printing y and z
it is giving
Thanks for the explanation !
@vijju123 seen u after 3 days !!
Hmm. I can think of 3 instances-
- When you become a 7 star
- When you get a good placement and job from college and your parents start looking for your
- When you decide to give us all a treat :3 :o
Third one is the one i expect to be the sooner one of all three. @vijju123
btw, Nice answer @aryanc403
Thank you @vijju123 @taran_1407 @worldunique
This was my first answer on codechef forum and got accepted.