Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Suggestion: Drop the signbit #142

Closed
dou4cc opened this issue Apr 17, 2018 · 10 comments
Closed

Suggestion: Drop the signbit #142

dou4cc opened this issue Apr 17, 2018 · 10 comments

Comments

@dou4cc
Copy link

dou4cc commented Apr 17, 2018

Before BigInt, the following usual equivalent implementations can all convert a to a number unless throw:

Number(a);
+a;
- -a;
1 * a;

Now:

a = 0n;
Number(a); // 0
+a; // TypeError
- -a; // 0n ← WTF??
1 * a; // TypeError

Suggestion: Drop the signbit of BigInt

@bakkot
Copy link
Contributor

bakkot commented Apr 17, 2018

This doesn't affect existing code unless someone adds new code to the page, so no, it wouldn't break the web. There may be existing code whose assumptions are no longer valid in the presence of new code, but that's true for many features.

I don't think avoiding this hazard is worth not having negative integers.

@littledan
Copy link
Member

Suggestion: Drop the signbit of BigInt

What would this mean?

@dou4cc
Copy link
Author

dou4cc commented Apr 17, 2018

This doesn't affect existing code unless someone adds new code to the page, so no, it wouldn't break the web.

Ok. So why forbid +0n? It is inconsistent.

@dou4cc
Copy link
Author

dou4cc commented Apr 17, 2018

Suggestion: Drop the signbit of BigInt

What would this mean?

It means that we can make BigInt unsigned since as a basis feature for scientific calculations, natural number is enough.

@bakkot
Copy link
Contributor

bakkot commented Apr 17, 2018

Ok. So why forbid +0n? It is inconsistent.

See #25.

@dou4cc
Copy link
Author

dou4cc commented Apr 17, 2018

Ok. So why forbid +0n? It is inconsistent.

See #25.

I mean otherwise it should be:

+0n === 0n

@dou4cc
Copy link
Author

dou4cc commented Apr 18, 2018

Without signbit, BigInt would become compatible with >>>, which is a win win.

@dou4cc dou4cc changed the title It may break the web Suggestion: Drop the signbit Apr 18, 2018
@dou4cc
Copy link
Author

dou4cc commented Apr 21, 2018

Quite strange:

String(0); // "0"

String(0n); // "0"

-{[Symbol.toPrimitive]: hint => {
	throw new EvalError(hint);
}}; // EvalError: number

-{[Symbol.toPrimitive]: () => "0"}; // -0

-{[Symbol.toPrimitive]: () => 0n}; // 0n

typeof 0n; // "bigint"

+{[Symbol.toPrimitive]: () => 0n}; // TypeError: Cannot convert a BigInt value to a number

@dou4cc dou4cc closed this as completed May 9, 2018
@littledan
Copy link
Member

These were all explicit design decisions, and I don't see any reason in this thread to change things. Feel free to reopen with more motivation.

@dou4cc
Copy link
Author

dou4cc commented May 9, 2018

Closed because the proposal seems not going to separate number and bigInt completely.

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

3 participants