-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thoughts on Math.sum/Math.product and implications for this proposal #23
Comments
Number.sum/BigInt.sum is far less weird than Math.sum/Math.bigSum, but it's pretty unfortunate we can't just have a single Math.sum that works with both. |
How so? There's several other Math operations which will remain Number-only ( And the overwhelming majority case is summing a list of Numbers; it would be a shame if users in the common case all had to remember that |
"BigUint" is both close to the full "BigInt", and also being a Typed Array means it's already sufficiently weird so as not to be an automatic precedent or convention. While I agree that would be a shame, I think sadly that's somewhat an unavoidable consequence of the committee's decision to minimize the ability to mix Numbers and BigInts - for example, |
Well, no, it's completely avoidable: |
right, but "bigSum" would imply "big sums" to me, not "sums of bigints", which is why i find that naming weird. |
I'd be fine with |
My vote is for In my view, the mixed-type In fact, one could argue that the unresolvable ambiguity of |
I'm thinking about adding two new methods for doing sum/product. They'd take iterables of numbers:
Math.sum([1, 2, 3]) === 6
.And of course if you pass
Math.sum
an empty array, you'd get0
out. But then these methods can't really work with BigInts at all: you can't distinguish "an empty array of Numbers" from "an empty array of BigInts", so you can't tell whether0
or0n
is the identity. And you can't reasonably haveMath.sum([1n])
give1n
but also haveMath.sum([])
give 0.So I'm thinking there should be separate
Math.sum
/Math.bigSum
methods, each of which only accepts values of one specific type.If committee agrees with that analysis, maybe that informs the design of this proposal? Everything currently in this proposal can get away with polymorphism, but that's not going to be true for every possible method, so maybe it will make more sense to split methods into Number/BigInt versions even when we could theoretically combine them. (see also #14)
Alternatively, I suppose, we could have
Number.sum
andBigInt.sum
. That would be pretty weird but it would at least avoid this tension.The text was updated successfully, but these errors were encountered: