Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MaxGraey/as-bignum
Fixed length big numbers for AssemblyScript 🚀
https://github.com/MaxGraey/as-bignum
assemblyscript bigdecimal bigint biginteger bignum fixed-point int128 typescript u128 u256 wasm webassembly
Last synced: 2 months ago
JSON representation
Fixed length big numbers for AssemblyScript 🚀
- Host: GitHub
- URL: https://github.com/MaxGraey/as-bignum
- Owner: MaxGraey
- License: apache-2.0
- Created: 2018-06-04T16:18:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-17T08:29:56.000Z (8 months ago)
- Last Synced: 2024-10-13T14:50:43.129Z (3 months ago)
- Topics: assemblyscript, bigdecimal, bigint, biginteger, bignum, fixed-point, int128, typescript, u128, u256, wasm, webassembly
- Language: TypeScript
- Homepage:
- Size: 3.69 MB
- Stars: 61
- Watchers: 6
- Forks: 19
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-assemblyscript - MaxGraey/as-bignum - Fixed length big numbers (Packages)
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(-32)
var c = new u128(0x1, -0xF);
var d = u128.from(0x0123456789ABCDEF); // same as u128.from(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());
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`](https://github.com/MaxGraey/as-bignum/blob/master/assembly/fixed/fp128.ts) generic fixed point signed typeÙ (very basic for now)
- [ ] `fp256` generic fixed point signed typeÙ---
- [ ] `safe.fp128` generic fixed point signed typeÙ
- [ ] `safe.fp256` generic fixed point signed typeÙÙ _typename_ `Q` _is a type representing count of fractional bits_