Skip to content

Commit 521d345

Browse files
brigandljharb
authored andcommitted
[Fix] differentiate -0 from 0
1 parent 7f4ca84 commit 521d345

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
3333
if (typeof obj === 'string') {
3434
return inspectString(obj);
3535
}
36+
if (typeof obj === 'number') {
37+
if (obj === 0) {
38+
return Infinity / obj > 0 ? '0' : '-0';
39+
}
40+
return String(obj);
41+
}
3642
else if (typeof obj === 'function') {
3743
var name = nameOf(obj);
3844
return '[Function' + (name ? ': ' + name : '') + ']';

test/number.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var inspect = require('../');
2+
var test = require('tape');
3+
4+
test('negative zero', function (t) {
5+
t.equal(inspect(0), '0');
6+
t.equal(inspect(-0), '-0');
7+
t.end();
8+
});

0 commit comments

Comments
 (0)