Flarnie,

Noticed JavaScript permits both negative and positive zero. They are equal, luckily, so it doesn't seem like a gotcha. Just made me smile.

> const positiveZero = 0;  
> const negativeZero = -0;  
> positiveZero === negativeZero  
true  
penryu,
@penryu@hachyderm.io avatar

@Flarnie This is one of the surprisingly few places where JavaScript's use of double precision floating point for all Numbers shows through.

You can see the same behavior in C/C++:

https://godbolt.org/z/h9qPrxxoG

graue,
@graue@social.coop avatar

@Flarnie that's really weird. Is there any way in which they behave differently other than how they display in a REPL?

BoydStephenSmithJr,
@BoydStephenSmithJr@hachyderm.io avatar

@graue @Flarnie 1/0 reduces to Infinity. 1/(-0) reduces to -Infinity.

IEEE floating point (both single and double precision) requires a negative zero, because having it for intermediate values sometimes prevents an incorrect (wrong sign) final value for some expressions.

graue,
@graue@social.coop avatar

@BoydStephenSmithJr @Flarnie Ack, this is cursed, though. Strict equal and not the same:

> let z = 0, nz = -0;

> z === nz
true
> 1/z === 1/nz
false

Flarnie,

Found one quirk - it is the only number for which Number(x.toString()) is not the same as x. They are still equal, but it removes the negative sign.

penryu,
@penryu@hachyderm.io avatar

@Flarnie Heh. This one is kinda quirky, yeah. Apparently a behavior of Number.toString(). TIL.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • anitta
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • megavids
  • JUstTest
  • All magazines