1# BigInt 2 3Class `Napi::Bigint` inherits from class [`Napi::Value`][]. 4 5A JavaScript BigInt value. 6 7## Methods 8 9### New 10 11```cpp 12static Napi::BigInt Napi::BigInt::New(Napi::Env env, int64_t value); 13static Napi::BigInt Napi::BigInt::New(Napi::Env env, uint64_t value); 14``` 15 16 - `[in] env`: The environment in which to construct the `Napi::BigInt` object. 17 - `[in] value`: The value the JavaScript `BigInt` will contain 18 19These APIs convert the C `int64_t` and `uint64_t` types to the JavaScript 20`BigInt` type. 21 22```cpp 23static Napi::BigInt Napi::BigInt::New(Napi::Env env, 24 int sign_bit, 25 size_t word_count, 26 const uint64_t* words); 27``` 28 29 - `[in] env`: The environment in which to construct the `Napi::BigInt` object. 30 - `[in] sign_bit`: Determines if the resulting `BigInt` will be positive or negative. 31 - `[in] word_count`: The length of the words array. 32 - `[in] words`: An array of `uint64_t` little-endian 64-bit words. 33 34This API converts an array of unsigned 64-bit words into a single `BigInt` 35value. 36 37The resulting `BigInt` is calculated as: (–1)<sup>`sign_bit`</sup> (`words[0]` 38× (2<sup>64</sup>)<sup>0</sup> + `words[1]` × (2<sup>64</sup>)<sup>1</sup> + …) 39 40Returns a new JavaScript `BigInt`. 41 42### Constructor 43 44```cpp 45Napi::BigInt(); 46``` 47 48Returns a new empty JavaScript `Napi::BigInt`. 49 50### Int64Value 51 52```cpp 53int64_t Napi::BigInt::Int64Value(bool* lossless) const; 54``` 55 56 - `[out] lossless`: Indicates whether the `BigInt` value was converted losslessly. 57 58Returns the C `int64_t` primitive equivalent of the given JavaScript 59`BigInt`. If needed it will truncate the value, setting lossless to false. 60 61### Uint64Value 62 63```cpp 64uint64_t Napi::BigInt::Uint64Value(bool* lossless) const; 65``` 66 67 - `[out] lossless`: Indicates whether the `BigInt` value was converted 68 losslessly. 69 70Returns the C `uint64_t` primitive equivalent of the given JavaScript 71`BigInt`. If needed it will truncate the value, setting lossless to false. 72 73### WordCount 74 75```cpp 76size_t Napi::BigInt::WordCount() const; 77``` 78 79Returns the number of words needed to store this `BigInt` value. 80 81### ToWords 82 83```cpp 84void Napi::BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words); 85``` 86 87 - `[out] sign_bit`: Integer representing if the JavaScript `BigInt` is positive 88 or negative. 89 - `[in/out] word_count`: Must be initialized to the length of the words array. 90 Upon return, it will be set to the actual number of words that would be 91 needed to store this `BigInt`. 92 - `[out] words`: Pointer to a pre-allocated 64-bit word array. 93 94Returns a single `BigInt` value into a sign bit, 64-bit little-endian array, 95and the number of elements in the array. 96 97[`Napi::Value`]: ./value.md 98