Follow-up from bug 1606568.
In GJS we'd find a few more BigInt APIs useful to have available for embedders. (More info: https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/524)
I'd propose to add the following APIs in js/public/BigInt.h:
* Convert the given BigInt to a Number value as if calling the Number
* constructor on it
* (https://tc39.es/ecma262/#sec-number-constructor-number-value). The value
* may be rounded if it doesn't fit without loss of precision.
extern JS_PUBLIC_API double BigIntToNumber(BigInt* bi);
* Return true if the given BigInt is negative.
extern JS_PUBLIC_API bool BigIntIsNegative(BigInt* bi);
* Return true if the given BigInt fits inside the given NumericT type without
* loss of precision, and store the value in the out parameter. Otherwise return
* false and leave the value of the out parameter unspecified.
template <typename NumericT, std::enable_if_t<std::is_integral_v<UnsignedIntT>>>
extern JS_PUBLIC_API bool BigIntFits(BigInt* bi, NumericT* out);
* Same as BigIntFits(), but checks if the value fits inside a JS Number value.
extern JS_PUBLIC_API bool BigIntFitsNumber(BigInt* bi, double* out);
* Convert the given BigInt to a String value as if toString() were called on
extern JS_PUBLIC_API JSString* BigIntToString(JSContext* cx, BigInt* bi);
#if defined(DEBUG) || defined(JS_JITSPEW)
* Print the given BigInt to stderr, useful for debuggers.
extern JS_PUBLIC_API void DumpBigInt(BigInt* bi);
Does this look like a good plan? Bikesheds welcome on the names and forms of the APIs.
Could also add the arithmetic operations as suggested in the original bug.
I would be willing to work on this and would like to get it in for ESR 91.