18c339a94Sopenharmony_ci# BigInt
28c339a94Sopenharmony_ci
38c339a94Sopenharmony_ciClass `Napi::Bigint` inherits from class [`Napi::Value`][].
48c339a94Sopenharmony_ci
58c339a94Sopenharmony_ciA JavaScript BigInt value.
68c339a94Sopenharmony_ci
78c339a94Sopenharmony_ci## Methods
88c339a94Sopenharmony_ci
98c339a94Sopenharmony_ci### New
108c339a94Sopenharmony_ci
118c339a94Sopenharmony_ci```cpp
128c339a94Sopenharmony_cistatic Napi::BigInt Napi::BigInt::New(Napi::Env env, int64_t value);
138c339a94Sopenharmony_cistatic Napi::BigInt Napi::BigInt::New(Napi::Env env, uint64_t value);
148c339a94Sopenharmony_ci```
158c339a94Sopenharmony_ci
168c339a94Sopenharmony_ci - `[in] env`: The environment in which to construct the `Napi::BigInt` object.
178c339a94Sopenharmony_ci - `[in] value`: The value the JavaScript `BigInt` will contain
188c339a94Sopenharmony_ci
198c339a94Sopenharmony_ciThese APIs convert the C `int64_t` and `uint64_t` types to the JavaScript
208c339a94Sopenharmony_ci`BigInt` type.
218c339a94Sopenharmony_ci
228c339a94Sopenharmony_ci```cpp
238c339a94Sopenharmony_cistatic Napi::BigInt Napi::BigInt::New(Napi::Env env,
248c339a94Sopenharmony_ci                  int sign_bit,
258c339a94Sopenharmony_ci                  size_t word_count,
268c339a94Sopenharmony_ci                  const uint64_t* words);
278c339a94Sopenharmony_ci```
288c339a94Sopenharmony_ci
298c339a94Sopenharmony_ci - `[in] env`: The environment in which to construct the `Napi::BigInt` object.
308c339a94Sopenharmony_ci - `[in] sign_bit`: Determines if the resulting `BigInt` will be positive or negative.
318c339a94Sopenharmony_ci - `[in] word_count`: The length of the words array.
328c339a94Sopenharmony_ci - `[in] words`: An array of `uint64_t` little-endian 64-bit words.
338c339a94Sopenharmony_ci
348c339a94Sopenharmony_ciThis API converts an array of unsigned 64-bit words into a single `BigInt`
358c339a94Sopenharmony_civalue.
368c339a94Sopenharmony_ci
378c339a94Sopenharmony_ciThe resulting `BigInt` is calculated as: (–1)<sup>`sign_bit`</sup> (`words[0]`
388c339a94Sopenharmony_ci× (2<sup>64</sup>)<sup>0</sup> + `words[1]` × (2<sup>64</sup>)<sup>1</sup> + …)
398c339a94Sopenharmony_ci
408c339a94Sopenharmony_ciReturns a new JavaScript `BigInt`.
418c339a94Sopenharmony_ci
428c339a94Sopenharmony_ci### Constructor
438c339a94Sopenharmony_ci
448c339a94Sopenharmony_ci```cpp
458c339a94Sopenharmony_ciNapi::BigInt();
468c339a94Sopenharmony_ci```
478c339a94Sopenharmony_ci
488c339a94Sopenharmony_ciReturns a new empty JavaScript `Napi::BigInt`.
498c339a94Sopenharmony_ci
508c339a94Sopenharmony_ci### Int64Value
518c339a94Sopenharmony_ci
528c339a94Sopenharmony_ci```cpp
538c339a94Sopenharmony_ciint64_t Napi::BigInt::Int64Value(bool* lossless) const;
548c339a94Sopenharmony_ci```
558c339a94Sopenharmony_ci
568c339a94Sopenharmony_ci - `[out] lossless`: Indicates whether the `BigInt` value was converted losslessly.
578c339a94Sopenharmony_ci
588c339a94Sopenharmony_ciReturns the C `int64_t` primitive equivalent of the given JavaScript
598c339a94Sopenharmony_ci`BigInt`. If needed it will truncate the value, setting lossless to false.
608c339a94Sopenharmony_ci
618c339a94Sopenharmony_ci### Uint64Value
628c339a94Sopenharmony_ci
638c339a94Sopenharmony_ci```cpp
648c339a94Sopenharmony_ciuint64_t Napi::BigInt::Uint64Value(bool* lossless) const;
658c339a94Sopenharmony_ci```
668c339a94Sopenharmony_ci
678c339a94Sopenharmony_ci - `[out] lossless`: Indicates whether the `BigInt` value was converted
688c339a94Sopenharmony_ci   losslessly.
698c339a94Sopenharmony_ci
708c339a94Sopenharmony_ciReturns the C `uint64_t` primitive equivalent of the given JavaScript
718c339a94Sopenharmony_ci`BigInt`. If needed it will truncate the value, setting lossless to false.
728c339a94Sopenharmony_ci
738c339a94Sopenharmony_ci### WordCount
748c339a94Sopenharmony_ci
758c339a94Sopenharmony_ci```cpp
768c339a94Sopenharmony_cisize_t Napi::BigInt::WordCount() const;
778c339a94Sopenharmony_ci```
788c339a94Sopenharmony_ci
798c339a94Sopenharmony_ciReturns the number of words needed to store this `BigInt` value.
808c339a94Sopenharmony_ci
818c339a94Sopenharmony_ci### ToWords
828c339a94Sopenharmony_ci
838c339a94Sopenharmony_ci```cpp
848c339a94Sopenharmony_civoid Napi::BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words);
858c339a94Sopenharmony_ci```
868c339a94Sopenharmony_ci
878c339a94Sopenharmony_ci - `[out] sign_bit`: Integer representing if the JavaScript `BigInt` is positive
888c339a94Sopenharmony_ci   or negative.
898c339a94Sopenharmony_ci - `[in/out] word_count`: Must be initialized to the length of the words array.
908c339a94Sopenharmony_ci   Upon return, it will be set to the actual number of words that would be
918c339a94Sopenharmony_ci   needed to store this `BigInt`.
928c339a94Sopenharmony_ci - `[out] words`: Pointer to a pre-allocated 64-bit word array.
938c339a94Sopenharmony_ci
948c339a94Sopenharmony_ciReturns a single `BigInt` value into a sign bit, 64-bit little-endian array,
958c339a94Sopenharmony_ciand the number of elements in the array.
968c339a94Sopenharmony_ci
978c339a94Sopenharmony_ci[`Napi::Value`]: ./value.md
98