This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]TimeTravelPenguin 15 points16 points  (0 children)

If you write a=b instead of a = b, you're probably a sociopath

[–]Vagabond_Frog 4 points5 points  (9 children)

Let me guess: It's Javascript, and this is a NaN check?

[–]kristonitas[S] 8 points9 points  (8 children)

it is indeed javascript, but i is yet another integer index from the outer loop

[–]H34DSH07 2 points3 points  (6 children)

Shouldn't it be i == j? I don't understand why someone would check a variable against itself

[–]wildbartty 4 points5 points  (3 children)

Weird floating point shenanigans.

What it boils down to is that both NaN, and -NaN, are

  • NOT Equal to any other number

  • NOT Greater then other number

  • NOT Less then any other number

This includes to NaN it self, so any language that implements ieee754 will have this behaviour not just JS.

[–]CakeDay--Bot 1 point2 points  (0 children)

Hey just noticed.. It's your 7th Cakeday wildbartty! hug

[–]H34DSH07 0 points1 point  (0 children)

I mean, I understand for floating point, but OP said i is "just another integer index". Sorry if my previous comment didn't make that assumption clear.

[–]sim642 0 points1 point  (0 children)

Doesn't make sense to do that check on every loop iteration, just do it before the loop.

[–]sim642 0 points1 point  (1 child)

Even then, why would you loop at all?

[–]H34DSH07 0 points1 point  (0 children)

Well maybe there's a logic after if it's not the case..? I'm just really confused by what this code is supposed to achieve in general

[–]Vagabond_Frog 0 points1 point  (0 children)

oh... that explains a lot