# as-bignum

> 128 and 256 bits integer and fixed point arithmetics for AssemblyScript. Also support checking overflow/underflow

Latest version **0.3.1** (published 2024-04-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install as-bignum
pnpm add as-bignum
yarn add as-bignum
bun add as-bignum
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2024-04-21 |
| First published | 2020-01-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 331.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Author | MaxGraey |
| Maintainers | maxgraey |
| Keywords | u128, u256, bignum, bigint, biginteger, fixed, wasm, webassembly, assemblyscript |

## Links

- npm: https://www.npmjs.com/package/as-bignum
- Repository: https://github.com/MaxGraey/as-bignum
- Issues: https://github.com/MaxGraey/as-bignum/issues
- npm.io page: https://npm.io/package/as-bignum

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2024-04-21
- 0.3.0 — 2023-09-24
- 0.2.40 — 2023-06-23
- 0.2.31 — 2023-04-19
- 0.2.30 — 2023-03-06
- 0.2.23 — 2022-08-05
- 0.2.22 — 2022-08-05
- 0.2.21 — 2022-07-18
- 0.2.20 — 2022-07-17
- 0.2.19 — 2022-07-17
- 0.2.18 — 2021-06-23
- 0.2.17 — 2021-06-01
- 0.2.16 — 2021-05-15
- 0.2.15 — 2021-02-26
- 0.2.14 — 2021-02-10
- … 19 more at https://npm.io/package/as-bignum/versions

## README

[![NPM registry](https://img.shields.io/npm/v/as-bignum.svg?style=for-the-badge)](https://www.npmjs.com/package/as-bignum)[![Build Status](https://img.shields.io/travis/com/MaxGraey/as-bignum/master?style=for-the-badge)](https://travis-ci.com/MaxGraey/as-bignum)[![NPM license](https://img.shields.io/badge/license-Apache%202.0-ba68c8.svg?style=for-the-badge)](LICENSE.md)

## WebAssembly fixed length big numbers written on [AssemblyScript](https://github.com/AssemblyScript/assemblyscript)

### Status: Work in progress

Provide wide numeric types such as `u128`, `u256`, `i128`, `i256` and fixed points and also its arithmetic operations.

Namespace `safe` contain equivalents with overflow/underflow traps.

All kind of types pretty useful for economical and cryptographic usages and provide deterministic behavior.

### Install

> yarn add as-bignum

or

> npm i as-bignum

### Usage via AssemblyScript

```ts
import { u128 } from "as-bignum/assembly";
// Before 0.20.x
// import { u128 } from "as-bignum";

declare function logF64(value: f64): void;
declare function logU128(hi: u64, lo: u64): void;

var a = u128.One;
var b = u128.from(-32); // same as u128.from<i32>(-32)
var c = new u128(0x1, -0xF);
var d = u128.from(0x0123456789ABCDEF); // same as u128.from<i64>(0x0123456789ABCDEF)
var e = u128.from('0x0123456789ABCDEF01234567');
var f = u128.fromString('11100010101100101', 2); // same as u128.from('0b11100010101100101')
var r = d / c + (b << 5) + e;

logF64(r.as<f64>());
logU128(r.hi, r.lo);
```

### Usage via JavaScript/Typescript

```ts
TODO
```

### List of types

- [x] [`u128`](https://github.com/MaxGraey/as-bignum/blob/master/assembly/integer/u128.ts) unsigned type (tested)
- [ ] [`u256`](https://github.com/MaxGraey/as-bignum/blob/master/assembly/integer/u256.ts) unsigned type (very basic)
- [ ] `i128` signed type
- [ ] `i256` signed type

---

- [x] [`safe.u128`](https://github.com/MaxGraey/as-bignum/blob/master/assembly/integer/safe/u128.ts) unsigned type (tested)

- [ ] `safe.u256` unsigned type
- [ ] `safe.i128` signed type
- [ ] `safe.i256` signed type

---

- [ ] [`fp128<Q>`](https://github.com/MaxGraey/as-bignum/blob/master/assembly/fixed/fp128.ts) generic fixed point signed type٭ (very basic for now)
- [ ] `fp256<Q>` generic fixed point signed type٭

---

- [ ] `safe.fp128<Q>` generic fixed point signed type٭
- [ ] `safe.fp256<Q>` generic fixed point signed type٭

٭ _typename_ `Q` _is a type representing count of fractional bits_

---
_Source: https://npm.io/package/as-bignum · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
