-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
### Fixed-point math library | ||
# Fixed-point math library | ||
|
||
The library implements basic math operations for 72/56 fixed-point values, and Log, Exp, Lgamma, BinCDF functions. | ||
|
||
### Motivation | ||
## 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 | ||
## Implementation | ||
|
||
[BinCDF](https://github.com/spacemeshos/fixed/blob/master/fixed.go#L110) is implemented with | ||
[incomplete Beta function](https://github.com/spacemeshos/fixed/blob/master/beta.go#L5) in standart way: | ||
``` | ||
[BinCDF](https://github.com/spacemeshos/fixed/blob/master/fixed.go#L110) is implemented with | ||
[incomplete Beta function](https://github.com/spacemeshos/fixed/blob/master/beta.go#L5) in standard way: | ||
|
||
```text | ||
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](https://github.com/spacemeshos/fixed/blob/master/log.go#L19), | ||
|
||
Fixed-point arithmetics and [Log](https://github.com/spacemeshos/fixed/blob/master/log.go#L19), | ||
[Exp](https://github.com/spacemeshos/fixed/blob/master/exp.go#L10), | ||
[Lgamma](https://github.com/spacemeshos/fixed/blob/master/lgamma.go#L4) | ||
functions are implemented with the **bits** go module and raw operations over 56-bit fractional part values in range [-7..7]. | ||
[Lgamma](https://github.com/spacemeshos/fixed/blob/master/lgamma.go#L4) functions are implemented with the | ||
**bits** go module and raw operations over 56-bit fractional part values in range [-7..7]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/spacemeshos/fixed | ||
|
||
go 1.20 | ||
go 1.23.2 |