bsv-fixmath
v1.0.1
Published
Fixed-point math for Bitcoin Script
Downloads
4
Readme
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;