-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Discussions around this proposal have shown that extending Math
functions with BigInt support is difficult (e.g.: transcendental functions are intractable; max
/min
run into surprisingly difficult "how to spec this?" questions for mixed inputs; etc), and while a few people have expressed support for getting a little closer to interchangeability of Numbers and BigInts, others have questioned the usefulness of such efforts.
At the same time, there is consistent demand for certain new, BigInt-only functions. Therefore, I'm inclined to think that bringing those into the language might be a "juicier" (more useful, more rewarding, more interesting) area for BigInt-related spec work.
In this very repository, issues #1, #2, and #12 are examples of such demand. The original BigInt proposal also collected four ideas for future proposals (with some overlap with the former set).
That leads to the following list of functions that could be spec'ed:
bitLength
(subsumes "truncatinglog2
")expMod
(combined exponentiation and modulus)fromString(..., radix)
gcd
(greatest common divisor)modInv
(modular multiplicative inverse)toByteArray
,fromByteArray
Of course, abs
, sign
, min
, max
as discussed here so far could also be included. (If they're even worth it; they're all one-liners.)
Where exactly to put these functions is an open question. I've used BigMathStrawman
in the title in reference to an earlier discussion; probably the BigInt
object is a good home for them, but there are alternatives.
The functions themselves also have various open questions. Some of them (in particular bitLength
and *ByteArray
, maybe the others too) need to decide how to handle negative BigInts. Some of them (expMod
, gcd
, modInv
) can reasonably be implemented in userspace (which doesn't mean that there can be no value in adding them to the language), others (bitLength
, fromString
, to/fromByteArray
) can get significant efficiency benefits from a native implementation (e.g. bitLength
is at least O(log n) in userspace, but O(1) natively). Some of them could be renamed (expMod
because it's conceptually an exp
followed by a %
, or modExp
because it's a "modular exp
"? modInv
because it's short, or modularInverse
because it's descriptive?) If this or another proposal decides to take on these functions, all those discussions can be had in detail.
(This is just a thought and an attempt to be constructive; feel free to close this issue if your mind is set that you don't want to go in this direction.)