stackblitz / core

Online IDE powered by Visual Studio Code ⚡️
https://stackblitz.com
MIT License
10.2k stars 884 forks source link

Negative zero #2741

Open yolodevz opened 10 months ago

yolodevz commented 10 months ago

Description

Math.sign(-0) produces incorrect output

Steps to Reproduce

  1. Go to https://stackblitz.com/edit/negative-zero?file=index.js
  2. Open console
  3. See that both logs produce 0
negative-zero-stackblitz

Expected Behavior

  1. Math.sign(-0) should output -0 instead of 0
  2. Math.sign(0) should output 0

Chrome console:

negative-zero-chrome-console

Additional Context

JS spec: https://262.ecma-international.org/9.0/#sec-ecmascript-language-types-number-type

Note that there is both a positive zero and a negative zero. For brevity, these values are also referred to for expository purposes by the symbols +0 and -0, respectively. (Note that these two different zero Number values are produced by the program expressions +0 (or simply 0) and -0.)

fvsch commented 9 months ago

Thanks for the detailed report @yolodevz!

Looks like something we should fix in our Console implementation.