Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Why normalize zero values? #97

Closed
Josh-Cena opened this issue Apr 23, 2023 · 2 comments
Closed

Why normalize zero values? #97

Josh-Cena opened this issue Apr 23, 2023 · 2 comments

Comments

@Josh-Cena
Copy link

Josh-Cena commented Apr 23, 2023

Every method that produces a set does a "If nextValue is -0𝔽, set nextValue to +0𝔽.". This looks unnecessary because we don't do the same normalization on this, and neither is this normalization expected. Since we use SameValueZero, there's no need to normalize zeros. This seems to be planned for removal: #75 (comment) but never addressed.

@bakkot
Copy link
Collaborator

bakkot commented Apr 23, 2023

I'm not sure I understand the question. Sets cannot contain -0 by construction. So whenever we're constructing a set by creating its [[SetData]] slot directly, we need to avoid putting -0 in it.

Since we use SameValueZero, there's no need to normalize zeros.

I don't know which use of SameValueZero you're talking about. There's one in SetDataHas, but that's not always sufficient - for example, consider

let minusZeroSet = new Set([0]);
minusZeroSet.keys = () => [-0].values();
console.log([...(new Set).union(minusZeroSet)]);

Without the normalization in step 7.b.ii of Set.prototype.union, that would result in [-0], which would be bad.

This seems to be planned for removal: #75 (comment) but never addressed.

The comment was addressed; the unnecessary cases were removed.

@Josh-Cena
Copy link
Author

Oops—you are right, sets cannot contain -0. That was my main confusion.

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants