bsv-fixmath
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

bsv-fixmath

Fixed-point implementations of exp, log, root and pow for Bitcoin SV. This repo contains two equivalent implementations, one in Typescript and one in sCrypt that compiles to Bitcoin Script.

Install with npm install bsv-fixmath.

Getting started

Compiling to Bitcoin Script (dist directory):

./getCompiler.sh && npm run build:scrypt

Convert your numbers to 64-bit fixed-point integers:

const fixedNum = BigInt(num * 2 ** 64)
int fixedNum = num << 64;

Here are all functions exposed by the library:

import { exp2, exp, mostSignificantBit, log2, log, log10, sqrt, root, pow } from "bsv-fixMath"

const fixedResult = exp(fixedNum)
const result = Number(fixedResult) / 2 ** 64
import "./fixMath.scrypt";

int fixedResult = FixMath.exp(fixedNum);
int result = fixedResult >> 64;

Readme

Keywords

Package Sidebar

Install

npm i bsv-fixmath

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

38.7 kB

Total Files

7

Last publish

Collaborators

  • merlinb