[@isdk/bigint](../README.md) / [Exports](../modules.md) / IBigInt

# Interface: IBigInt

The unified interface for Big Integer

**`Remarks`**

The operator method prefix

* `i`: perform operation in-place, storing the result in the host object (on which the method was invoked). Might be used to avoid number allocation costs

**`Example`**

```typescript
import BigInteger from '@isdk/bigint'
const a = new BigInteger(9)
const b = new BigInteger(6)
// perform addition on `a` and `b`, storing the result in `a`
a.iadd(b)
console.log(a.toString()) // prints "15"
```

## Implemented by

- [`BigIntNative`](../classes/BigIntNative.md)

## Table of contents

### Methods

- [abs](IBigInt.md#abs)
- [add](IBigInt.md#add)
- [bitLength](IBigInt.md#bitlength)
- [byteLength](IBigInt.md#bytelength)
- [clone](IBigInt.md#clone)
- [dec](IBigInt.md#dec)
- [equal](IBigInt.md#equal)
- [gcd](IBigInt.md#gcd)
- [getBit](IBigInt.md#getbit)
- [gt](IBigInt.md#gt)
- [gte](IBigInt.md#gte)
- [iadd](IBigInt.md#iadd)
- [idec](IBigInt.md#idec)
- [iinc](IBigInt.md#iinc)
- [ileftShift](IBigInt.md#ileftshift)
- [imod](IBigInt.md#imod)
- [imul](IBigInt.md#imul)
- [inc](IBigInt.md#inc)
- [irightShift](IBigInt.md#irightshift)
- [isEven](IBigInt.md#iseven)
- [isNegative](IBigInt.md#isnegative)
- [isOne](IBigInt.md#isone)
- [isZero](IBigInt.md#iszero)
- [isub](IBigInt.md#isub)
- [leftShift](IBigInt.md#leftshift)
- [lt](IBigInt.md#lt)
- [lte](IBigInt.md#lte)
- [mod](IBigInt.md#mod)
- [modExp](IBigInt.md#modexp)
- [modInv](IBigInt.md#modinv)
- [mul](IBigInt.md#mul)
- [rightShift](IBigInt.md#rightshift)
- [sub](IBigInt.md#sub)
- [toNumber](IBigInt.md#tonumber)
- [toString](IBigInt.md#tostring)
- [toUint8Array](IBigInt.md#touint8array)

## Methods

### abs

▸ **abs**(): [`IBigInt`](IBigInt.md)

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:195](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L195)

___

### add

▸ **add**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger addition

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to add |

#### Returns

[`IBigInt`](IBigInt.md)

this + x.

#### Defined in

[src/IBigint.ts:94](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L94)

___

### bitLength

▸ **bitLength**(): `number`

Compute bit length

#### Returns

`number`

Bit length.

#### Defined in

[src/IBigint.ts:221](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L221)

___

### byteLength

▸ **byteLength**(): `number`

Compute byte length

#### Returns

`number`

Byte length.

#### Defined in

[src/IBigint.ts:227](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L227)

___

### clone

▸ **clone**(): [`IBigInt`](IBigInt.md)

return a new IBigInteger object with the same value

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:25](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L25)

___

### dec

▸ **dec**(`n?`): [`IBigInt`](IBigInt.md)

IBigInteger decrement

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n?` | `number` | (optional) Value to decrement, defaults to 1 |

#### Returns

[`IBigInt`](IBigInt.md)

this - 1.

#### Defined in

[src/IBigint.ts:87](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L87)

___

### equal

▸ **equal**(`x`): `boolean`

Whether this value is equal to x

#### Parameters

| Name | Type |
| :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) |

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:161](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L161)

___

### gcd

▸ **gcd**(`n`): [`IBigInt`](IBigInt.md)

Compute greatest common divisor between this and n

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n` | [`IBigInt`](IBigInt.md) | Operand |

#### Returns

[`IBigInt`](IBigInt.md)

gcd

#### Defined in

[src/IBigint.ts:140](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L140)

___

### getBit

▸ **getBit**(`i`): `number`

Get value of i-th bit

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `i` | `number` | Bit index |

#### Returns

`number`

Bit value.

#### Defined in

[src/IBigint.ts:215](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L215)

___

### gt

▸ **gt**(`x`): `boolean`

Whether this value is greater than x

#### Parameters

| Name | Type |
| :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) |

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:182](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L182)

___

### gte

▸ **gte**(`x`): `boolean`

Whether this value is greater than or equal to x

#### Parameters

| Name | Type |
| :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) |

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:189](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L189)

___

### iadd

▸ **iadd**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger addition in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to add |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:43](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L43)

___

### idec

▸ **idec**(`n?`): [`IBigInt`](IBigInt.md)

IBigInteger decrement number n in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n?` | `number` | (optional) Value to decrement, defaults to 1 |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:37](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L37)

___

### iinc

▸ **iinc**(`n?`): [`IBigInt`](IBigInt.md)

IBigInteger increment number n in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n?` | `number` | (optional) Value to increment, defaults to 1 |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:31](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L31)

___

### ileftShift

▸ **ileftShift**(`x`): [`IBigInt`](IBigInt.md)

Shift this to the left by x, in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Shift value |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:67](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L67)

___

### imod

▸ **imod**(`m`): [`IBigInt`](IBigInt.md)

Compute value modulo m, in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `m` | [`IBigInt`](IBigInt.md) | Modulo |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:61](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L61)

___

### imul

▸ **imul**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger multiplication in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to multiply |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:55](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L55)

___

### inc

▸ **inc**(`n?`): [`IBigInt`](IBigInt.md)

IBigInteger increment

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n?` | `number` | (optional) Value to increment, defaults to 1 |

#### Returns

[`IBigInt`](IBigInt.md)

this + 1.

#### Defined in

[src/IBigint.ts:80](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L80)

___

### irightShift

▸ **irightShift**(`x`): [`IBigInt`](IBigInt.md)

Shift this to the right by x, in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Shift value |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:73](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L73)

___

### isEven

▸ **isEven**(): `boolean`

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:194](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L194)

___

### isNegative

▸ **isNegative**(): `boolean`

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:193](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L193)

___

### isOne

▸ **isOne**(): `boolean`

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:192](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L192)

___

### isZero

▸ **isZero**(): `boolean`

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:191](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L191)

___

### isub

▸ **isub**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger subtraction in place

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to subtract |

#### Returns

[`IBigInt`](IBigInt.md)

#### Defined in

[src/IBigint.ts:49](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L49)

___

### leftShift

▸ **leftShift**(`x`): [`IBigInt`](IBigInt.md)

Shift this to the left by x

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Shift value |

#### Returns

[`IBigInt`](IBigInt.md)

this << x.

#### Defined in

[src/IBigint.ts:147](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L147)

___

### lt

▸ **lt**(`x`): `boolean`

Whether this value is less than x

#### Parameters

| Name | Type |
| :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) |

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:168](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L168)

___

### lte

▸ **lte**(`x`): `boolean`

Whether this value is less than or equal to x

#### Parameters

| Name | Type |
| :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) |

#### Returns

`boolean`

#### Defined in

[src/IBigint.ts:175](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L175)

___

### mod

▸ **mod**(`m`): [`IBigInt`](IBigInt.md)

Compute value modulo m

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `m` | [`IBigInt`](IBigInt.md) | Modulo |

#### Returns

[`IBigInt`](IBigInt.md)

this mod m.

#### Defined in

[src/IBigint.ts:115](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L115)

___

### modExp

▸ **modExp**(`e`, `n`): [`IBigInt`](IBigInt.md)

Compute modular exponentiation
Much faster than this.exp(e).mod(n)

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `e` | [`IBigInt`](IBigInt.md) | Exponent |
| `n` | [`IBigInt`](IBigInt.md) | Modulo |

#### Returns

[`IBigInt`](IBigInt.md)

this ** e mod n.

#### Defined in

[src/IBigint.ts:124](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L124)

___

### modInv

▸ **modInv**(`n`): [`IBigInt`](IBigInt.md)

Compute the inverse of this value modulo n
Note: this and and n must be relatively prime

**`Throws`**

if the inverse does not exist

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `n` | [`IBigInt`](IBigInt.md) | Modulo |

#### Returns

[`IBigInt`](IBigInt.md)

x such that this*x = 1 mod n

#### Defined in

[src/IBigint.ts:133](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L133)

___

### mul

▸ **mul**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger multiplication

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to multiply |

#### Returns

[`IBigInt`](IBigInt.md)

this * x.

#### Defined in

[src/IBigint.ts:108](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L108)

___

### rightShift

▸ **rightShift**(`x`): [`IBigInt`](IBigInt.md)

Shift this to the right by x

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Shift value |

#### Returns

[`IBigInt`](IBigInt.md)

this >> x.

#### Defined in

[src/IBigint.ts:154](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L154)

___

### sub

▸ **sub**(`x`): [`IBigInt`](IBigInt.md)

IBigInteger subtraction

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | [`IBigInt`](IBigInt.md) | Value to subtract |

#### Returns

[`IBigInt`](IBigInt.md)

this - x.

#### Defined in

[src/IBigint.ts:101](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L101)

___

### toNumber

▸ **toNumber**(): `number`

Get this value as an exact Number (max 53 bits)
Fails if this value is too large

#### Returns

`number`

the number value

#### Defined in

[src/IBigint.ts:208](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L208)

___

### toString

▸ **toString**(): `string`

Get this value as a string

#### Returns

`string`

this value.

#### Defined in

[src/IBigint.ts:201](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L201)

___

### toUint8Array

▸ **toUint8Array**(`endian?`, `length?`): `Uint8Array`

Get Uint8Array representation of this number

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `endian?` | `string` | Endianess of output array (defaults to 'be') |
| `length?` | `number` | Of output array |

#### Returns

`Uint8Array`

#### Defined in

[src/IBigint.ts:235](https://github.com/isdk/bigint.js/blob/c098291/src/IBigint.ts#L235)
