百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

fixed

> 数据库
开源

用于 Go 的高性能固定小数点数学库

352 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 Go 的高性能固定小数点数学库

Summary

A fixed place numeric library designed for performance.

The C++ version is available here.

All numbers have a fixed 7 decimal places (18 digits total), and the maximum permitted value is +- 99999999999, or just under 100 billion. NaN is supported.

The library is safe for concurrent use. Fixed values are immutable. 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

using Go 1.21.5 cpu: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz BenchmarkAddFixed-8 1000000000 0.9627 ns/op 0 B/op 0 allocs/op BenchmarkAddDecimal-8 17871763 66.52 ns/op 80 B/op 2 allocs/op BenchmarkAddBigInt-8 125826048 9.562 ns/op 0 B/op 0 allocs/op BenchmarkAddBigFloat-8 18763552 63.51 ns/op 48 B/op 1 allocs/op BenchmarkMulFixed-8 335886367 3.538 ns/op 0 B/op 0 allocs/op BenchmarkMulDecimal-8 18164803 66.12 ns/op 80 B/op 2 allocs/op BenchmarkMulBigInt-8 100000000 10.41 ns/op 0 B/op 0 allocs/op BenchmarkMulBigFloat-8 50151100 23.93 ns/op 0 B/op 0 allocs/op BenchmarkDivFixed-8 328157694 3.722 ns/op 0 B/op 0 allocs/op BenchmarkDivDecimal-8 2558497 461.7 ns/op 384 B/op 12 allocs/op BenchmarkDivBigInt-8 33726384 34.68 ns/op 8 B/op 1 allocs/op BenchmarkDivBigFloat-8 10757650 110.1 ns/op 24 B/op 2 allocs/op BenchmarkCmpFixed-8 1000000000 0.2519 ns/op 0 B/op 0 allocs/op BenchmarkCmpDecimal-8 171236422 6.926 ns/op 0 B/op 0 allocs/op BenchmarkCmpBigInt-8 250970304 4.791 ns/op 0 B/op 0 allocs/op BenchmarkCmpBigFloat-8 271898336 4.428 ns/op 0 B/op 0 allocs/op BenchmarkStringFixed-8 23637406 50.30 ns/op 24 B/op 1 allocs/op BenchmarkStringNFixed-8 23457960 51.85 ns/op 24 B/op 1 allocs/op BenchmarkStringDecimal-8 5763308 210.2 ns/op 56 B/op 4 allocs/op BenchmarkStringBigInt-8 11742596 114.0 ns/op 16 B/op 1 allocs/op BenchmarkStringBigFloat-8 3003280 395.3 ns/op 176 B/op 7 allocs/op BenchmarkWriteTo-8 38573978 43.13 ns/op 27 B/op 0 allocs/op

The "decimal" above is the common shopspring decimal library

Compatibility with SQL drivers

By default Fixed implements decomposer.Decimal interface for database drivers that support it. To use sql.Scanner and driver.Valuer implementation flag sql_scanner must be specified on build.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gofinancialfixed-pointgolangmath

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库