Skip to content

-0 is not normalized #9

Description

@acutmore

In JavaScript Map and Set do not distinguish 0 and -0 as different keys, instead -0 is normalized to 0.

This leads to the following 'bug':

const { tuple } = require("immutable-tuple");

if (Math.random() > 0.5) {
    tuple(Object, -0); // sometimes create this first
} else {
    tuple(Object, 0); // other times create this first
}

function isNegativeZero(n) {
  return Object.is(n, -0);
}

console.log(isNegativeZero(tuple(Object, -0)[1])); // sometimes 'true', sometimes 'false'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions