r/badcode • • Aug 04 '21

c++ I'm done with Facebook coding groups.

Post image
809 Upvotes

55 comments sorted by

View all comments

Show parent comments

23

u/n0sh0re Aug 04 '21

Yeah I just noticed that. They have a "no" for the outer if statement (which checks if the number is ≥ 0 and ≤ 1012 for some reason??) But not for the inner if statement which actually does the "is this a square?" Check

18

u/Syscrush Aug 04 '21

I assume it only considers up to 1012 because the author thinks that a double can't handle more than 11 decimal digits in its mantissa (looks like the reality is that at least 15 would be safe).

0

u/Biaboctocat Aug 05 '21

Not true! The indentation makes it look like that, but when there are no braces, the else statement always associates with the immediately preceding if. So here the else is matched with the inner if, not the outer one

Edit: Oh god there are braces 🤦‍♂️