tc39 / proposal-bigint-math

Draft specification for supporting BigInts in JavaScript’s Math methods.
https://tc39.es/proposal-bigint-math/
BSD 3-Clause "New" or "Revised" License
36 stars 2 forks source link

BigInt imul? #9

Closed js-choi closed 2 years ago

js-choi commented 2 years ago

I know of no use case for imul accepting BigInts, but at least its mathematical behavior would be well defined and exact.

On the other hand, making imul polymorphic could make optimization for asm.js more difficult. See also the original BigInt proposal’s “Don’t break asm.js” section.

@ljharb has said—and I agree—that that BigInts and Numbers should always be interchangeable by default, unless that would cause silent precision loss – i.e., unless there's a strong reason they should not be (https://github.com/js-choi/proposal-bigint-math/issues/8#issuecomment-912126129).

Under this framework, it’d be good to know if a polymorphic imul would worsen asm.js optimization, which would count as a “strong reason [BigInts and Numbers] should not be [interchangeable]”. CC: @syg, @codehag.

ljharb commented 2 years ago

While it'd be good to know regardless, I was under the impression that asm.js was no longer a priority in favor of WASM.

syg commented 2 years ago

For BigInts, Math.imul would be a mystification of *, so I see no reason to support it.

I don't really agree with argument that BigInts and Numbers should be interchangeable by default. Why should they be interchangeable by default? Floating point and arbitrary precision ints are drastically different and choice of which to use should be thought through by the programmer. We can't have even most of Math work for BigInts, even if you would like them to be interchangeable by default, that intuition just won't hold up in practice, so why push for it?

js-choi commented 2 years ago

Closing. There are no known use cases for BigInt imul, and it may interfere with asm.js.

See also https://github.com/tc39/proposal-bigint-math/issues/13#issuecomment-919472001 and https://github.com/tc39/proposal-bigint-math/issues/14#issuecomment-918663577.