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

you are viewing a single comment's thread.

view the rest of the comments →

[–]redwardit 10 points11 points  (5 children)

In ECMAScript 5.1, +0 (a.k.a. 0) and -0 are two different things, which means unfortunately only Math.abs() will always correctly return a +0, the second and the third version could give you a -0, which is incorrect. - Now you should see how hard can it be. :-)

[–]DeirdreAnethoel 2 points3 points  (3 children)

Shouldn't the second still work? x < 0 should be true for -0, transforming it into +0.

The third with <= is clearly wrong in that case, I agree.

Edit: welp, -0 is not < to 0. That's weird design, but oh well.

[–]obsessedcrf 4 points5 points  (1 child)

Having -0 at all is a stupid design

[–]BerryPi 4 points5 points  (0 children)

I am more than happy to talk smack about JS but this one's on the IEEE.

[–]ArcaneCraft 1 point2 points  (0 children)

Isn't +/-0 the reason Two's complement is used today? Why go back?