high performance fixed decimal place math library for Go

Overview

Summary

A fixed place numeric library designed for performance.

All numbers have a fixed 7 decimal places, and the maximum permitted value is +- 99999999999, or just under 100 billion.

The library is safe for concurrent use. It has built-in support for binary and json marshalling.

It is ideally suited for high performance trading financial systems. All common math operations are completed with 0 allocs.

Design Goals

Primarily developed to improve performance in go-trader. Using Fixed rather than decimal.Decimal improves the performance by over 20%, and a lot less GC activity as well. You can review these changes under the 'fixed' branch.

If you review the go-trader code, you will quickly see that I use dot imports for the fixed and common packages. Since this is a "business/user" app and not systems code, this provides 2 major benefits: less verbose code, and I can easily change the implementation of Fixed without changing lots of LOC - just the import statement, and some of the wrapper methods in common.

The fixed.Fixed API uses NaN for reporting errors in the common case, since often code is chained like:

   result := someFixed.Mul(NewS("123.50"))

and this would be a huge pain with error handling. Since all operations involving a NaN result in a NaN, any errors quickly surface anyway.

Performance

BenchmarkAddFixed-2         	2000000000	         0.85 ns/op	       0 B/op	       0 allocs/op
BenchmarkAddDecimal-2       	 3000000	       472 ns/op	     400 B/op	      10 allocs/op
BenchmarkAddBigInt-2        	100000000	        18.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAddBigFloat-2      	20000000	       109 ns/op	      48 B/op	       1 allocs/op
BenchmarkMulFixed-2         	200000000	         6.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkMulDecimal-2       	20000000	        96.0 ns/op	      80 B/op	       2 allocs/op
BenchmarkMulBigInt-2        	100000000	        22.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkMulBigFloat-2      	30000000	        50.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkDivFixed-2         	100000000	        19.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkDivDecimal-2       	 1000000	      1206 ns/op	     928 B/op	      22 allocs/op
BenchmarkDivBigInt-2        	20000000	        67.6 ns/op	      48 B/op	       1 allocs/op
BenchmarkDivBigFloat-2      	10000000	       148 ns/op	      64 B/op	       2 allocs/op
BenchmarkCmpFixed-2         	2000000000	         0.28 ns/op	       0 B/op	       0 allocs/op
BenchmarkCmpDecimal-2       	100000000	        10.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkCmpBigInt-2        	200000000	         8.10 ns/op	       0 B/op	       0 allocs/op
BenchmarkCmpBigFloat-2      	200000000	         8.39 ns/op	       0 B/op	       0 allocs/op
BenchmarkStringFixed-2      	20000000	        76.1 ns/op	      32 B/op	       1 allocs/op
BenchmarkStringNFixed-2     	20000000	        72.9 ns/op	      32 B/op	       1 allocs/op
BenchmarkStringDecimal-2    	 5000000	       328 ns/op	     144 B/op	       5 allocs/op
BenchmarkStringBigInt-2     	10000000	       212 ns/op	      80 B/op	       3 allocs/op
BenchmarkStringBigFloat-2   	 3000000	       568 ns/op	     272 B/op	       8 allocs/op
BenchmarkWriteTo-2          	20000000	        69.9 ns/op	      27 B/op	       0 allocs/op

The "decimal" above is the common shopspring decimal library

Issues
Owner
robert engels
All work here is personal and has no connection with any business venture or employer past or present.
robert engels
Arbitrary-precision fixed-point decimal numbers in go

decimal Arbitrary-precision fixed-point decimal numbers in go. Note: Decimal library can "only" represent numbers with a maximum of 2^31 digits after

Spring Engineering 3.1k Jun 12, 2021
high performance fixed decimal place math library for Go

Summary A fixed place numeric library designed for performance. All numbers have a fixed 7 decimal places, and the maximum permitted value is +- 99999

robert engels 265 May 17, 2021
Arbitrary-precision decimals for Go

apd apd is an arbitrary-precision decimal package for Go. apd implements much of the decimal specification from the General Decimal Arithmetic descrip

CockroachDB 358 May 23, 2021
A fast SAT solver

Gini SAT Solver The Gini sat solver is a fast, clean SAT solver written in Go. It is to our knowledge the first ever performant pure-Go SAT solver mad

IRI France R&D Open Organisation 119 Jun 10, 2021
Go language bindings for the COIN-OR Linear Programming library

clp Description The clp package provides a Go interface to the COIN-OR Linear Programming (CLP) library, part of the COIN-OR (COmputational INfrastruc

Los Alamos National Laboratory 23 Jun 3, 2021
Implements a simple floating point arithmetic expression evaluator in Go (golang).

evaler https://github.com/soniah/evaler Package evaler implements a simple floating point arithmetic expression evaluator. Evaler uses Dijkstra's Shun

Sonia Hamilton 44 Apr 1, 2021
Document mathematical Go code beautifully

mathfmt Document mathematical Go code beautifully. Write mathematical formulae in a LaTeX-ish syntax Super/subscripts formatted with Unicode character

Michael McLoughlin 158 Jun 2, 2021
This is a go implementation of Segmented Sieve and non Segmented sieve to produce prime numbers concurrently.

Prime This is a Go library to produce prime numbers using all available cpu cores. Installation $ go get github.com/kavehmz/prime Usage package main

Kaveh Mousavi Zamani 21 Nov 7, 2020
Go bindings for fftw3

Go bindings for FFTW v3.2.2 Maintained by Jonathan Wills: [email protected] Feel free to email me patches, suggestions or bugs. FFTW homepage: htt

null 38 Nov 22, 2020
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Montana Flynn 2k Jun 13, 2021
Go library that makes it easy to work with physical types, e.g. distances, velocities and angles.

Units Use at your own risk Note that this library is NOT production ready. If you want to use it anyway, contributions and bug reports are welcome! Br

Sindre Røkenes Myren 19 Feb 26, 2021
Go Library [DEPRECATED]

Tideland Go Library Description The Tideland Go Library contains a larger set of useful Google Go packages for different purposes. ATTENTION: The cell

Tideland 194 Feb 1, 2021
cartconvert is a package providing a set of cartography functions for the Go programming language

cartconvert - a cartography package This is the home of the cartconvert project. You can find it online at http://cartconvert.allowed.org/ Cartconvert

Johann Höchtl 32 Nov 17, 2019
GNU GSL Statistics library (v1.15, GPLv3) implemented in Go

Statistics Pure Go implementation of the GSL Statistics library. For the API overview see Godoc. Why create this repository when there is also "github

grd 74 Mar 12, 2021