128 and 256 bits integer and fixed point arithmetics for AssemblyScript. Also support checking overflow/underflow
npm install as-bignum
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.
> yarn add as-bignum
or
> npm i as-bignum
``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
var c = new u128(0x1, -0xF);
var d = u128.from(0x0123456789ABCDEF); // same as u128.from
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);
`
`ts`
TODO
- [x] u128 unsigned type (tested)
- [ ] u256 unsigned type (very basic)
- [ ] i128 signed typei256
- [ ] signed type
---
- [x] safe.u128 unsigned type (tested)
- [ ] safe.u256 unsigned typesafe.i128
- [ ] signed typesafe.i256
- [ ] signed type
---
- [ ] fp128
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_