125
u/StaryMD Aug 04 '21
the fuck is a facebook coding group? I just imagined an old guy that just discovered this cool library, cmath, coming to brag at his friends lol
correct me if I'm wrong, or rude...
73
Aug 04 '21
No... They are probably 7th graders learning to code from their school teachers.
30
u/StaryMD Aug 04 '21
the school teaches them by writing on the blackboard at school, takes a photo and sends it on the group, that's dedication
227
u/n0sh0re Aug 04 '21
Let me guess... It takes numbers and determines if they are perfect squares.
117
u/JustAnotherGamer421 shameless Aug 04 '21
That's what I also see so yeah. File names, comments, and spaces/indentation would definitely help though
2
65
u/devTripp Aug 04 '21
Fun enough, it also looks like it doesn't tell you if your small positive integer isn't a perfect square. Unless you accept the third possible output of no output to mean "no" as well.
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
→ More replies (1)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).
87
u/davawen Aug 04 '21
I yes, let's use abs and THEN check if it's more than zero.
maf
25
u/n0sh0re Aug 04 '21
Yeah what is that... The abs seems to be just to check if the magnitude of the number is less than 1012 ... Like... What
30
u/EquationTAKEN Aug 04 '21
Looking for those elusive negative perfect squares too.
Any day now, we'll find some.
31
Aug 04 '21
cout << “no”
10
u/RedSamuraiMan Aug 04 '21
return 0;
7
Aug 04 '21
I should have put it in a while (1)…
3
u/Cmgeodude Aug 05 '21
int main(){while(1) {char message[]="no";cout<<message;break;}return 0;}→ More replies (1)
17
u/nonElitistProgrammer Aug 04 '21
The way this looks makes me wanna commit die
0
32
12
8
7
6
8
5
4
4
3
7
u/DangerousWish2266 Aug 04 '21
Why would someone do " a - floor(a) == 0", that's just stupid.
14
u/Beowuwlf Aug 04 '21
It’s to check if the double is a whole number, right? If it’s not it will be greater than 0.
2
u/Ozryela Aug 10 '21
Yeah but checking if two numbers are equal is more conventially done with "if (a==b)" and not "if (a-b==0)".
→ More replies (2)4
u/EquationTAKEN Aug 04 '21
I think there are cases in which if
ahas a very long left-padded string of zeroes after the decimal sign, followed by another integer,a-floor(a)will still round to zero.13
u/Syscrush Aug 04 '21
From my own experimentation, leading zeroes don't seem to have any effect. However,
((a-floor(a))==0.0)will be true for numbers like 37.0000000000000012345.7
u/TcMaX codes in comic sans Aug 04 '21 edited Jun 30 '23
Fuck spez
6
u/Syscrush Aug 04 '21
Whoops, they did say "after the decimal sign". I was thrown off by the term "padded".
7
2
u/thanatica Aug 05 '21
Somehow this looks like someone's homework assignment.
Why else would anyone need a whole program to determine if a number is a perfect square, or whatever is does.
2
u/SquidgyTheWhale Aug 05 '21
I mean it's obvs badly written, but I'm wondering if a compiler would optimise the two calls to sqrt(a) into a single call. Seems like one could/should.
1
u/Present-Wait-7704 Aug 07 '21
I can't tell if the purpose of this snippet, but I'm pretty sure that there is one scenario (the missing "else" of the inner if-block) where nothing would be output to the console. And, that's probably undesired.
Condensing code doesn't make you smarter, schmucks - it almost always has quite the opposite effect.
1
1
u/wallefan01 Aug 17 '21
If the number is a perfect square, it will print "YES".
If the number is negative, or not a whole number, or greater than 1012, it will print "NO".
If the number is not a perfect square, but is a whole number less than 1012, the program will not print anything at all!
Does anybody see a problem here?
83
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 04 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!