项目作者: MaxGraey

项目描述 :
Fixed length big numbers for AssemblyScript 🚀
高级语言: WebAssembly
项目地址: git://github.com/MaxGraey/as-bignum.git
创建时间: 2018-06-04T16:18:29Z
项目社区:https://github.com/MaxGraey/as-bignum

开源协议:Apache License 2.0

下载


NPM registryBuild StatusNPM license

WebAssembly fixed length big numbers written on 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

  1. import { u128 } from "as-bignum/assembly";
  2. // Before 0.20.x
  3. // import { u128 } from "as-bignum";
  4. declare function logF64(value: f64): void;
  5. declare function logU128(hi: u64, lo: u64): void;
  6. var a = u128.One;
  7. var b = u128.from(-32); // same as u128.from<i32>(-32)
  8. var c = new u128(0x1, -0xF);
  9. var d = u128.from(0x0123456789ABCDEF); // same as u128.from<i64>(0x0123456789ABCDEF)
  10. var e = u128.from('0x0123456789ABCDEF01234567');
  11. var f = u128.fromString('11100010101100101', 2); // same as u128.from('0b11100010101100101')
  12. var r = d / c + (b << 5) + e;
  13. logF64(r.as<f64>());
  14. logU128(r.hi, r.lo);

Usage via JavaScript/Typescript

  1. TODO

List of types

  • u128 unsigned type (tested)
  • u256 unsigned type (very basic)
  • i128 signed type
  • i256 signed type

  • [x] safe.u128 unsigned type (tested)

  • [ ] safe.u256 unsigned type

  • safe.i128 signed type
  • safe.i256 signed type

  • fp128<Q> 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