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