/fixed

Package fixed implements fixed-point integer types. [Based on golang.org/x/image/math/fixed]

Primary LanguageGoApache License 2.0Apache-2.0

Fixed-point math library

The library implements basic math operations for 72/56 fixed-point values, and Log, Exp, Lgamma, BinCDF functions.

Motivation

There is no efficient golang implementation for fixed-point math with a high-precision bincdf function.

The library uses a 56-bit fractional part to achieve maximum performance on math functions like Log, Exp, and Lgamma.

Implementation

BinCDF is implemented with incomplete Beta function in standart way:

Iₓ(a,b) = (xᵃ*(1-x)ᵇ)/(a*B(a,b)) * (1/(1+(d₁/(1+(d₂/(1+...))))))   
(xᵃ*(1-x)ᵇ)/B(a,b) = exp(lgamma(a+b) - lgamma(a) - lgamma(b) + a*log(x) + b*log(1-x))   
d_{2m+1} = -(a+m)(a+b+m)x/((a+2m)(a+2m+1))   
d_{2m}   = m(b-m)x/((a+2m-1)(a+2m))   

Fixed-point arithmetics and Log, Exp, Lgamma functions are implemented with the bits go module and raw operations over 56-bit fractional part values in range [-7..7].