1.0.1 • Published 3 years ago

bsv-fixmath v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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;