

GitHub - robaho/fixed: high performance fixed decimal place math library for Go
source link: https://github.com/robaho/fixed
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

readme.md
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-8 2000000000 0.84 ns/op 0 B/op 0 allocs/op BenchmarkAddDecimal-8 3000000 464 ns/op 400 B/op 10 allocs/op BenchmarkAddBigInt-8 100000000 19.2 ns/op 0 B/op 0 allocs/op BenchmarkAddBigFloat-8 20000000 110 ns/op 48 B/op 1 allocs/op BenchmarkMulFixed-8 200000000 6.19 ns/op 0 B/op 0 allocs/op BenchmarkMulDecimal-8 20000000 98.3 ns/op 80 B/op 2 allocs/op BenchmarkMulBigInt-8 100000000 22.4 ns/op 0 B/op 0 allocs/op BenchmarkMulBigFloat-8 30000000 50.4 ns/op 0 B/op 0 allocs/op BenchmarkDivFixed-8 100000000 20.1 ns/op 0 B/op 0 allocs/op BenchmarkDivDecimal-8 1000000 1189 ns/op 928 B/op 22 allocs/op BenchmarkDivBigInt-8 20000000 72.8 ns/op 48 B/op 1 allocs/op BenchmarkDivBigFloat-8 10000000 156 ns/op 64 B/op 2 allocs/op BenchmarkCmpFixed-8 2000000000 0.28 ns/op 0 B/op 0 allocs/op BenchmarkCmpDecimal-8 100000000 10.8 ns/op 0 B/op 0 allocs/op BenchmarkCmpBigInt-8 200000000 8.01 ns/op 0 B/op 0 allocs/op BenchmarkCmpBigFloat-8 200000000 8.50 ns/op 0 B/op 0 allocs/op BenchmarkStringFixed-8 20000000 97.7 ns/op 16 B/op 1 allocs/op BenchmarkStringDecimal-8 5000000 335 ns/op 144 B/op 5 allocs/op BenchmarkStringBigInt-8 10000000 215 ns/op 80 B/op 3 allocs/op BenchmarkStringBigFloat-8 3000000 586 ns/op 272 B/op 8 allocs/op
The "decimal" above is the common shopspring decimal library
Recommend
-
90
Fun with DDC
-
53
version 3.0! · ericlagergren/decimal · GitHub
-
38
README.md PHP Decimal
-
24
供稿 | Hadoop Team 编辑 | 顾欣怡 本文3058字,预计阅读时间10分钟
-
61
一、症状 一天,金融分析团队的同事报告了一个问题,他们发现在两个生产环境中 (为了区分,命名为 环境 A 和 B ), Spark 大版本均为 2.3。但是,当运行同样的 SQL 语句,对结果进行对比后,却发现 ...
-
11
I’ve been a software developer at EBANX since 2016. There we have a mechanism called Release Candidate . Every time we deploy something new to our monolith PHP system we end up deploying it first to the rele...
-
5
Description This PR optimizes the udivmod_1e19 function, which is used for formatting 128-bit integers, based on the algorithm provided in [1]. This optimization improves performance of formatting 128-bit inte...
-
5
Small Fixed-Point Decimals (fp3.Decimal) When you have small and simple f...
-
5
Ecma TC39 JavaScript Decimal proposal The TC39 Decimal proposal is an investigation into adding a built-in data type in JavaScript to represent base-10 decimal numbers. This whole proposal is basically a big open question, and we'd...
-
9
round-decimal Decimal rounding with ULP. Warning Work in process Installation npm install -D round-decimal
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK