Merge pull request #1058 from messense/bigint-zero
This commit is contained in:
commit
9f66ca2818
6 changed files with 15 additions and 0 deletions
|
@ -64,6 +64,9 @@ impl FromNapiValue for BigInt {
|
|||
|
||||
words.set_len(word_count as usize);
|
||||
}
|
||||
if word_count == 0 {
|
||||
words = vec![0];
|
||||
}
|
||||
Ok(BigInt {
|
||||
sign_bit: sign_bit == 1,
|
||||
words,
|
||||
|
|
|
@ -31,6 +31,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function bigintAdd(a: bigint, b: bigint): bigint␊
|
||||
export function createBigInt(): bigint␊
|
||||
export function createBigIntI64(): bigint␊
|
||||
export function bigintGetU64AsString(bi: bigint): string␊
|
||||
export function getCwd(callback: (arg0: string) => void): void␊
|
||||
export function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void␊
|
||||
export function optionStart(callback: (arg0: string | undefined | null, arg1: string) => void): void␊
|
||||
|
|
Binary file not shown.
|
@ -43,6 +43,7 @@ import {
|
|||
bigintAdd,
|
||||
createBigInt,
|
||||
createBigIntI64,
|
||||
bigintGetU64AsString,
|
||||
callThreadsafeFunction,
|
||||
threadsafeFunctionThrowError,
|
||||
asyncPlus100,
|
||||
|
@ -423,6 +424,10 @@ BigIntTest('create BigInt i64', (t) => {
|
|||
t.is(createBigIntI64(), BigInt(100))
|
||||
})
|
||||
|
||||
BigIntTest('BigInt get_u64', (t) => {
|
||||
t.is(bigintGetU64AsString(BigInt(0)), '0')
|
||||
})
|
||||
|
||||
BigIntTest('js mod test', (t) => {
|
||||
t.is(xxh64Alias(Buffer.from('hello world')), BigInt('1116'))
|
||||
t.is(xxh3.xxh3_64(Buffer.from('hello world')), BigInt('1116'))
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -21,6 +21,7 @@ export function asyncMultiTwo(arg: number): Promise<number>
|
|||
export function bigintAdd(a: bigint, b: bigint): bigint
|
||||
export function createBigInt(): bigint
|
||||
export function createBigIntI64(): bigint
|
||||
export function bigintGetU64AsString(bi: bigint): string
|
||||
export function getCwd(callback: (arg0: string) => void): void
|
||||
export function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void
|
||||
export function optionStart(callback: (arg0: string | undefined | null, arg1: string) => void): void
|
||||
|
|
|
@ -17,3 +17,8 @@ fn create_big_int() -> BigInt {
|
|||
fn create_big_int_i64() -> i64n {
|
||||
i64n(100)
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn bigint_get_u64_as_string(bi: BigInt) -> String {
|
||||
bi.get_u64().1.to_string()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue