Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result when logging subnormal floating-point number to console. #17500

Closed
ealmansi opened this issue Dec 6, 2017 · 4 comments
Closed
Labels
util Issues and PRs related to the built-in util module.

Comments

@ealmansi
Copy link

ealmansi commented Dec 6, 2017

  • Version: 8.9.1, 8.9.2, 9.x
  • Platform: Linux d0cc2382da37 4.4.0-101-generic 124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 Linux
  • Subsystem: console

Logging a subnormal floating-point number to console prints -0 instead of the correct number when passed as first argument to console.log. It prints the correct number if passed in as the second argument.

Steps to reproduce:

$ node
console.log(-5e-324);
console.log('', -5e-324); 

Expected output:

-5e-324
-5e-324

Actual output:

-0
-5e-324

Additional info:
I tested this code sample and can confirm incorrect output for versions 8.9.1, 8.9.2, and 9.x.
The same code sample produces the expected output in version 8.3.

@ealmansi ealmansi changed the title Incorrect result when logging subnormal floating point number to console. Incorrect result when logging subnormal floating-point number to console. Dec 6, 2017
@ealmansi
Copy link
Author

ealmansi commented Dec 6, 2017

cc @jpdjere

@vsemozhetbyt
Copy link
Contributor

FWIW, the output in the Chrome and Node.js REPL differ here:
Node.js canary with V8 6.5:

> -5e-324
-0
> ' ' + -5e-324
' -5e-324'

Google Chrome 65.0.3286.0:

-5e-324
-5e-324
' ' + -5e-324
" -5e-324"

@devsnek
Copy link
Member

devsnek commented Dec 6, 2017

this error comes from formatNumber in util.js:

if (-1 / value === -Infinity)
  return fn('-0', 'number');

value === 0 && -1 / value === -Infinity should fix this:

@ealmansi ealmansi closed this as completed Dec 6, 2017
@ealmansi ealmansi reopened this Dec 6, 2017
@mscdex mscdex added util Issues and PRs related to the built-in util module. v8.x and removed v8.x labels Dec 7, 2017
@BridgeAR
Copy link
Member

This already got fixed by #17507

Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants