惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
G
GRAHAM CLULEY
P
Privacy International News Feed
The Hacker News
The Hacker News
Forbes - Security
Forbes - Security
U
Unit 42
N
News and Events Feed by Topic
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cisco Blogs
A
About on SuperTechFans
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
I
Intezer
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
F
Full Disclosure
S
Secure Thoughts
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
W
WeLiveSecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Project Zero
Project Zero
Recorded Future
Recorded Future
Cyberwarzone
Cyberwarzone
S
Security Affairs
AWS News Blog
AWS News Blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
Vercel News
Vercel News
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Register - Security
The Register - Security
S
Schneier on Security
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
L
LINUX DO - 最新话题
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog

Show HN

GitHub - flightdeckhq/flightdeck: Observability and control plane for AI agents. CSP Radar GitHub - Light-Heart-Labs/DreamServer: Turn your PC, Mac, or Linux box into an AI server. LLM inference, chat UI, voice, agents, workflows, RAG, and image generation. GitHub - Diplomat-ai/diplomat-agent-ts: What can your TypeScript AI agent do to the real world? Scan your code. See which tool calls have zero checks Code Block Selector - Visual Studio Marketplace Prometheus dependency graph — interactive showcase | Riftmap Show HN: I made a vi-like modal keyboard plugin for Figma GitHub - run-llama/liteparse: A fast, helpful, and open-source document parser GitHub - dalemyers/Roar: A macOS CLI tool for notifications GitHub - district-solutions/open-agent-tools-coder: Enables small-to-large self-hosted ai models to use local source code when running tool-calling agentic workloads. We actively data mine 20,900+ (2+ TB) popular github repos using large and small ai models to create reuseable: json, markdown and parquet files for local-first tool-calling models. GitHub - progapandist/stripeek: A local TUI proxy for real-time Stripe API debugging, built for navigating complex payloads fast. GitHub - sir1st/hermes-desktop: All-in-one cross-platform desktop app for Hermes Agent — bundles Python + hermes-agent + hermes-web-ui GitHub - astefanutti/shaderbang: Shebang for Shaders Show HN: Generate Claude Code Workflows using Spec Driven Development approach GitHub - nixys/nxs-universal-chart: The Helm chart you can use to install any of your applications into Kubernetes/OpenShift Show HN: AI agents for UK GDAD PCF roles and their skills The Two Pillars: Mixer Mode and Meta-Software in the Reorganization of Software Work After AI GitHub - JaiCode08/teleport-env What 1,000+ Harness Experiments Taught Me About Self-Improving Agents Show HN: Liiists, a Markdown-first, iOS and CLI list app SwiperTab – Get this Extension for 🦊 Firefox (en-US) GitHub - kouhxp/fftext: Summarize, explain, fact-check, or translate any text, URL, or file. No GPU. No cloud. One command GitHub - sweetpad-dev/sweetpad: Develop Swift/iOS projects using VSCode GitHub - dogmaticdev/IRON: IRON a.k.a. Intermediate Representation Object Notation is a Interpreter/Database that is used to create Programming Languages. GitHub - sjhalani7/vaen: Package your AI coding harness into a portable .agent file, and share it across repos, teams, & the community without ever having to copy-paste instructions, skills, MCP config, or secrets. Show HN: Gandalf the Grader Show HN: Citadeld – replay any CI failure locally from a single file GitHub - tdortman/cuSBF: High-Performance GPU Super Bloom Filter coral-ai/claude-code-token-xray at main · Coral-Bricks-AI/coral-ai GitHub - ulyssestenn/funes: Funes is a Git-based framework for LLM-managed knowledge work: an AI Librarian ingests raw sources, builds an interlinked Markdown knowledge base, and uses it to produce cited reports, analyses, and other outputs. GitHub - ThatXliner/gah: Git Add Hunk, built for agents to use GitHub - harmont-dev/harmont-cli: Command-line client for the Harmont CI platform GitHub - brooksmcmillin/mcp-authflow: OAuth 2.0 Authorization Server framework for MCP servers GitHub - javaid-codes/audit-supply-chain-agents GitHub - amorey/gochan: A small library of common channel architectures for Go, inspired by Rust GitHub - arifozgun/OpenGem: Free, Open-Source AI API Gateway with Gemini, OpenAI & Anthropic Compatibility in 1 file GitHub - Pranesh950/BioPetals: 🌸 Run BIOxAI models at home, BitTorrent-style. Fine-tuning and inference up to 10x faster than offloading GitHub - cnguyen14/bounty-doctor: Diagnose a GitHub bounty issue before you waste hours: detects honeypot scam repos, AI-bot attempt swarms, and stale contests. Show HN: CoreMCP – MCP Server for On-Prem DBs Show HN: KittyHTML – Render HTML/CSS as an inline image in your terminal GitHub - bingud/filemat: Web-based file manager Show HN: TruthLens – Free multi-signal deepfake image detector GitHub - apexlocal-jz/claude-usage-tray: Windows system-tray app showing your Claude Code rate-limit usage at a glance. Zero deps, ~300 lines of PowerShell. Cross-IDE (works regardless of VS Code, Cursor, plain terminal). Release v0.1.2.1 · kouhxp/yapsnap GitHub - noopolis/moltnet: Self-hostable chat network for AI agents. Pre-built bridges for Claude Code, Codex, and the Claws. Rooms, DMs, history. No Slack bots, no Matrix, no glue code. GitHub - tamerh/enju: Coordinating Humans, AI Agents, and Compute as Peers on a Shared Workflow Graph Show HN: Continuity-auth – Respect-weighted rate limits for the open web GitHub - luml-ai/luml: AI lifecycle platform where engineers and agents track experiments, train models, and ship to production. GitHub - mrdanielcasper/CoreTex: A UNIX-inspired, biomimetic, flat-file AI harness and knowledge engine. GitHub - clemg/pierre-github: Pierre's diffs.com and trees.software for Github GitHub - lyriks-io/unspaghettit: Behavior-driven AI development without prompt spaghetti. GitHub - sofumel/claude-handoff-revive: Resume Claude Code work after rate/usage/context limits without replaying the prior transcript. Auto-saves at 90%/95% usage. Plugin-installable, 10 languages. GitHub - dotexorg/saferpc: Typed, end-to-end encrypted RPC over any bidirectional channel. GitHub - BeeZeeAgent/beezee: Agent harness orchestration Legato Next.js Boilerplate for Internal Tools · CoreUI GitHub - clark-labs-inc/clark-hash: Clark Hash, 32x smaller searchable sketches for embeddings GitHub - ZeroPointRepo/youtube-mcp: The fastest YouTube transcript + YouTube search MCP for AI agents. Try for free. Typing Mastery — climb toward 100+ WPM, deliberately GitHub - Andebugulin/Awareen GitHub - fayzan123/claude-workflow-composer: Visual desktop app for composing multi-agent coding workflows. Drag agents, attach skills and MCPs, wire handoffs, export to .claude/ GitHub - harshaneel/humanize: Best static AI text humanizer. Two research-grounded skills that work in any LLM (Claude, ChatGPT, Gemini, Codex): humanize beats perplexity-based detectors, ai-check produces forensic scoring with evidence-quoted flags. Nine levers, 50+ peer-reviewed sources, 2024-2026 detection literature. GitHub - StackOneHQ/stack-nudge GitHub - nodes-app/swift-markdown-engine: A native AppKit Markdown editor for macOS, built on TextKit 2 and bridged to SwiftUI. We hardened an LLM agent. Each defense we added made it more exploitable. GitHub - alkait/WhatsKept: Agent-queryable WhatsApp history from an iOS backup — a single Go binary. GitHub - octelium/cordium: Open-source, general-purpose sandbox platform for devs and AI agents that provides identity-based secure access to infrastructure without credentials. WAR.GOV/UFO Microfilm5 GitHub - scosman/videowright: Build animated explainer videos with your coding agent GitHub - dipankar/dscode: The code editor you can take apart. GitHub - zoharbabin/web-researcher-mcp: MCP server (Go) for AI assistants: web search, content extraction, academic/patent/news research. Multi-provider routing, 4-tier scraping, search lenses. Works with Claude, Cursor, and any MCP client. GitHub - ruvnet/RuView: π RuView turns commodity WiFi signals into real-time spatial intelligence, vital sign monitoring, and presence detection — all without a single pixel of video. GitHub - scanaislop/aislop: Catch the slop AI coding agents leave in your code: narrative comments, swallowed exceptions, as-any casts, dead code, oversized functions. 50+ rules across 7 languages (TypeScript, JavaScript, Python, Go, Rust, Ruby, PHP). Sub-second, deterministic, no LLM at runtime. MIT-licensed. GitHub - kouhxp/cheap-im: CPU-only voice agent approximating Thinking Machines' Interaction Models demo GitHub - unprovable/OrchidMantis: Orchid Mantis — standalone framework for Zero-Knowledge Proofs of eXploit (ZKPoX). GitHub - MarcellM01/TinySearch: Shrink the web for your local LLMs! GitHub - pileax-ai/pileax: PileaX is an all-in-one AI knowledge base system. 🍀 GitHub - TangibleResearch/Halgorithem: A Algo designed to detect AI Hallucitions GitHub - DO-SAY-GO/freelang: I love freelang GitHub - CarpseDeam/Aura-IDE: An AI coding harness that shaped itself - Planner/Worker agents, repo awareness, surgical edits, validation, recovery, and safe diff approvals. GitHub - chojs23/concord: A feature-rich TUI client for Discord GitHub - tommyjepsen/awesome-ux-skills: UX & AI Product designs skills you can use today in Claude Code GitHub - aerf-spec/aerf: Agent Evidence Receipt Format (AERF) — an open specification for tamper-evident, independently verifiable records of AI agent actions. GitHub - kklimuk/docx-cli: CLI for AI agents (Claude, Codex) to read, edit, and comment on .docx files with full format fidelity. GitHub - Jwrede/tokentoll: Catch LLM cost changes in code review. Infracost for LLM spend. GitHub - samchon/ttsc: A `typescript-go` toolchain for compiler-powered plugins and type-safe execution + 500x faster lint integrated into compiler GitHub - Higangssh/homebutler: 🏠 Manage your homelab from chat. Single binary, zero dependencies. GitHub - olalie/tapmap: See where your computer connects and what stands out on a live world map. GitHub - matisiekpl/neond: DX-focused control plane for Postgres dedicated to non-critical workloads. Your postgres:latest replacement 🐘 GitHub - Diplomat-ai/diplomat-agent: What can your AI agent do to the real world? Scan your code. See which tool calls have zero checks GitHub - Bajusz15/beacon: Open-source agent for secure remote access, monitoring, and deploys across home-lab and self-hosted machines like Raspberry Pi, N100, or any Linux server. Open web based TTY or tunnel Home Assistant and other local services securely without opening ports. BigTech AI News - Chrome 应用商店 GitHub - vinhnx/VTCode: VT Code is an open-source coding agent with LLM-native code understanding and robust shell safety. Supports multiple LLM providers with automatic failover and efficient context management. GitHub - michaelaz774/decision-engine: A decision operating system for startup founders, powered by Claude Code. Synthesizes wisdom from 25+ legendary founders and investors into interactive AI-driven decision frameworks. GitHub - Chrilleweb/dotenv-diff: Validate environment variable usage in your codebase GitHub - Lumen-Labs/brainapi2: BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications. GitHub - familiar-software/familiar: Let AI watch you work. Familiar lets your AI update its memory, skills, and knowledge by watching your screen. GitHub - skorotkiewicz/rudo: A small, elegant dock for Wayland GitHub - muxshed/shed: One stream in, or many. Every destination, simultaneously. No cloud middleman, no per-channel fees, no limits. make sidebar/address bar rounded corner toggleable
GitHub - AlexandrosKyriakakis/zerodecimal: Zero-allocation, panic-free decimal arithmetic for HFT-grade Go. No big.Int, no GC pressure, fastest in its class.
alexandrosky · 2026-06-13 · via Show HN

Zero-allocation, panic-free, fixed-point decimals for latency-critical Go.

Why another decimal library

  • Strictly zero heap allocations. Parsing, arithmetic, comparison, rounding, conversions, and every Unmarshal/Scan path perform exactly zero heap allocations — success and error paths alike — enforced by testing.AllocsPerRun gates in the default test suite (alloc_test.go).
  • Faster than every Go decimal library we could find. The committed benchstat comparisons show a −35% time geomean against quagmt/udecimal (the previous fastest) and −90% against shopspring/decimal (benchmarks/bench-vs-*.txt).
  • Bit-exact. Every operation is differentially checked against shopspring/decimal's unbounded arithmetic — including an iff proof for every returned overflow — deterministically in the default suite (crosscheck_test.go) and by 23 fuzz targets (fuzz_test.go).
  • Panic-free. Fallible operations return zero-allocation sentinel errors (errors.go) and the fuzz suite requires every target to be total — no input, including garbage binary payloads, may panic the library.

Install

go get github.com/AlexandrosKyriakakis/zerodecimal
import "github.com/AlexandrosKyriakakis/zerodecimal" // package zerodecimal

Requires Go 1.26+. The library has zero runtime dependencies.

price, err := zerodecimal.NewFromString("99.99")
if err != nil {
    return err
}
qty := zerodecimal.NewFromInt(3)

total, err := price.Mul(qty)
if err != nil {
    return err
}
fmt.Println(total)                // 299.97
fmt.Println(total.StringFixed(4)) // 299.9700

Runnable examples for parsing, arithmetic, rounding, JSON, and SQL live in example_test.go.

Design

type Decimal struct {
    coef u128  // |value| · 10^prec, 0 ≤ coef < 2^128
    neg  bool
    prec uint8 // fractional digits, 0..19
}

A Decimal is a 24-byte pointer-free value: copy it freely, compare it cheaply, pack it densely. The domain is |value| < 2^128 / 10^prec — up to 39 significant digits with up to 19 fractional. There is no big.Int anywhere in the package: every operation runs on fixed-width 128/256-bit integer math, so nothing can escape to the heap and out-of-domain results return ErrOverflow instead of degrading into arbitrary-precision slowness. The zero value is the canonical decimal zero, ready to use; no operation produces a negative zero.

Reciprocal division is the headline optimization. Decimal rescaling, rounding, formatting, and division all reduce to dividing by powers of ten, and zerodecimal never asks the hardware divider to do it: 64-bit dividends use precomputed Granlund–Montgomery–Warren multiply-high magics, and 128/256-bit dividends chain Möller–Granlund 2-by-1 steps off a precomputed reciprocal table (div10.go, tables generated and re-proven against bits.Div64 and big.Int in tables_test.go). A multiply-high plus a shift replaces an 18-cycle DIV — and for 128-bit dividends, two dependent DIVs — which is where most of the headroom over udecimal comes from.

Div uses adaptive precision: the result is the exact quotient truncated at the largest precision ≤ DefaultPrec (19 by default) whose coefficient still fits 128 bits, so huge quotients degrade precision gracefully and ErrOverflow is reserved for integer quotients that genuinely exceed 2^128.

Because == compares representations, an arithmetic result of 1.50 differs from a parsed 1.5 under ==; use Equal or Cmp for numeric comparison. Parsing trims trailing fractional zeros; arithmetic never does (it would tax the hot path); formatting trims at output.

Error model

All sentinels live in errors.go, are returned bare (never wrapped, except Scan's unsupported-type message), and match with errors.Is. The constructors and arithmetic operations have panicking twins for call sites with proven bounds; rows marked below have none.

Operation Possible sentinels Panicking twin
New ErrOverflow, ErrPrecOutOfRange MustNew
NewFromString, ParseBytes ErrEmptyString, ErrMaxStrLen, ErrInvalidFormat, ErrOverflow, ErrPrecOutOfRange RequireFromString
NewFromStringTrunc, ParseBytesTrunc ErrEmptyString, ErrMaxStrLen, ErrInvalidFormat, ErrOverflow
NewFromFloat, NewFromFloat32 ErrInvalidFloat, ErrOverflow, ErrPrecOutOfRange RequireFromFloat
NewFromHiLo ErrPrecOutOfRange
Add, Sub, Mul ErrOverflow MustAdd, MustSub, MustMul
Div ErrDivideByZero, ErrOverflow MustDiv
QuoRem, Mod ErrDivideByZero, ErrOverflow MustQuoRem, MustMod
Sum, Avg ErrOverflow MustSum, MustAvg
IntPart ErrIntPartOverflow
UnmarshalText, UnmarshalJSON the parse sentinels
UnmarshalBinary ErrInvalidBinaryData
Scan the parse sentinels, ErrInvalidFloat, ErrScanNil, ErrScanType

Everything else is infallible: NewFromInt/NewFromInt32/NewFromUint64, Neg, Abs, Sign, the Is* predicates, Cmp and the comparison family, Min/Max, the entire rounding family, Prec, ToHiLo, String, StringFixed, AppendFixed, and InexactFloat64. AppendText, AppendBinary, the Marshal* methods, and Value return an error only to satisfy their interfaces — it is always nil.

Allocation guarantees

Exactly what alloc_test.go enforces with testing.AllocsPerRun on every make test run, across six value shapes (small integers, typical prices, full 19-digit precision, extreme precision mismatch, near-2^128 coefficients, negatives), on success and error paths:

Allocations Operations Gate
exactly 0 NewFromString, ParseBytes, Add, Sub, Mul, Div, QuoRem, Mod, Cmp, Equal, Neg, Abs, Sign, Round, RoundBank, RoundUp, RoundDown, RoundCeil, RoundFloor, Truncate, Floor, Ceil, IntPart, InexactFloat64, NewFromFloat, AppendText, AppendFixed, AppendBinary, Min, Max, MustAdd, UnmarshalText, UnmarshalJSON, UnmarshalBinary, Scan (string and []byte) TestAllocsZero
exactly 1 String (outside the cache window), StringFixed — the returned string itself TestAllocsOne
exactly 1 MarshalText, MarshalJSON, MarshalBinary — the returned slice, sized exactly TestAllocsCodecMarshal
exactly 0 String and Value on values inside the small-value cache window (−1000.00..+1000.00, ≤ 2 places) TestAllocsStringCached, TestAllocsSQLValueCached
exactly 2 Value outside the cache window — the canonical string plus boxing it into driver.Value TestAllocsSQLValueUncached

The counts are asserted as exact, not upper bounds, so a regression in either direction fails the suite. Since the steady state allocates nothing, zerodecimal generates no GC pressure regardless of GOGC.

Parsing rules

Grammar: ['+'|'-'] digits ['.' digits] [('e'|'E') ['+'|'-'] digits], ASCII only, at most 200 bytes.

Accepted:

  • plain literals: "123", "-4.20", "+1", redundant zeros ("00012.3400"12.34)
  • scientific notation: "1.23e4"12300, "1E-7"0.0000001 (required for JSON float interop)
  • up to 39 significant digits: "340282366920938463463374607431768211455" (= 2^128−1) parses; one more unit is ErrOverflow

Rejected:

  • ""ErrEmptyString; input over 200 bytes → ErrMaxStrLen
  • "1." and ".1"ErrInvalidFormat: both sides of the dot need a digit (deliberately stricter than shopspring), as do ".", "-", "1..2", "1e", "1e+"
  • whitespace, underscores, non-ASCII digits, "NaN", "Inf"ErrInvalidFormat
  • more than 19 fractional digits → ErrPrecOutOfRange (strict variants)

The Trunc variants (NewFromStringTrunc, ParseBytesTrunc) replace ErrPrecOutOfRange with truncation toward zero at 19 fractional digits (possibly to exactly zero) and accept any mantissa within the 200-byte input cap (ErrMaxStrLen still applies) whenever the truncated value is representable; grammar violations and genuinely unrepresentable values still error. Results are always canonical: trailing fractional zeros are trimmed ("1.500" parses identically to "1.5") and parsing never allocates — not even on failure.

Rounding modes

places counts fractional digits; places ≥ d.Prec() returns d unchanged. The whole family is infallible — the increment can never overflow — and rounding a negative value to zero yields the canonical unsigned zero.

Method Mode 2.5 3.5 -2.5
Round(0) half away from zero (shopspring Round) 3 4 -3
RoundBank(0) half to even (banker's) 2 4 -2
RoundUp(0) away from zero 3 4 -3
RoundDown(0) / Truncate(0) toward zero 2 3 -2
RoundCeil(0) toward +∞ 3 4 -2
RoundFloor(0) toward −∞ 2 3 -3

Floor() and Ceil() are RoundFloor(0) and RoundCeil(0). Every mode is pinned tie-by-tie against its shopspring equivalent in crosscheck_test.go and fuzzed in fuzz_test.go.

Benchmarks

The comparative suite lives in benchmarks/ — a separate Go module, so the competitor dependencies never touch the library's go.mod. Full committed results: bench-vs-udecimal.txt, bench-vs-shopspring.txt, bench-vs-alpacadecimal.txt, bench-vs-ericlagergren.txt; methodology and the deliberate semantic asymmetries are documented in benchmarks/README.md.

Against quagmt/udecimal — the fastest existing Go decimal — zerodecimal is faster on 89 of the 90 op × shape rows and statistically tied on the remaining one (MarshalJSON/small_int):

goos: darwin
goarch: arm64
cpu: Apple M1 Pro
                          │   udecimal   │             zerodecimal             │
                          │    sec/op    │   sec/op     vs base                │
Add/typical_price-10         4.673n ± 0%   2.375n ± 0%  -49.18% (p=0.000 n=10)
Mul/typical_price-10         6.234n ± 0%   2.350n ± 0%  -62.29% (p=0.000 n=10)
Div/typical_price-10         12.93n ± 1%   11.70n ± 1%   -9.51% (p=0.000 n=10)
QuoRem/typical_price-10     13.455n ± 2%   3.155n ± 0%  -76.56% (p=0.000 n=10)
Cmp/typical_price-10         5.291n ± 0%   3.108n ± 2%  -41.26% (p=0.000 n=10)
Parse/typical_price-10       14.32n ± 0%   12.75n ± 0%  -10.96% (p=0.000 n=10)
String/typical_price-10      32.46n ± 1%   25.89n ± 1%  -20.24% (p=0.000 n=10)
geomean                      15.50n        10.07n       -35.03%

Against shopspring/decimal, the de-facto standard:

                          │  shopspring   │             zerodecimal             │
                          │    sec/op     │   sec/op     vs base                │
Add/typical_price-10        39.975n ± 2%   2.375n ± 0%  -94.06% (p=0.000 n=10)
Mul/typical_price-10        40.375n ± 1%   2.350n ± 0%  -94.18% (p=0.000 n=10)
Div/typical_price-10        210.35n ± 1%   11.70n ± 1%  -94.44% (p=0.000 n=10)
RoundBank/typical_price-10 353.250n ± 2%   4.677n ± 1%  -98.68% (p=0.000 n=10)
Parse/typical_price-10       75.92n ± 2%   12.75n ± 0%  -83.21% (p=0.000 n=10)
String/typical_price-10     106.50n ± 2%   25.89n ± 1%  -75.69% (p=0.000 n=10)
geomean                      93.42n        10.07n       -89.59%

Allocations are 0 on every row where any competitor manages 0, and 0 on many where they do not (e.g. udecimal's Mul/large allocates 160 B/op across 4 allocations; zerodecimal allocates nothing).

Known trade-offs

Allocation floors accepted by design (from benchmarks/README.md):

  • String: 1 alloc outside the cache window — a string-returning API must allocate its immutable result; the rendering itself is a stack buffer.
  • MarshalText/MarshalJSON/MarshalBinary: 1 alloc — callers own and may mutate marshal results, so sharing cached bytes is off the table; the slice is sized exactly.
  • Value: 2 allocs outside the cache window — the canonical string plus boxing into the driver.Value interface; there is no cheaper portable shape.

PGO

PGO attaches to binaries, not libraries — so zerodecimal cannot ship it, but your build can claim it. The hot paths are written PGO-friendly: no interfaces or indirect calls anywhere (devirtualization is never needed), and the slow arms (addSlow, mulSlow, the multi-limb division bodies) are deliberately outlined into small functions that profile-driven inlining can promote straight into your hot loops past the default inlining budget.

  1. Collect a CPU profile from production or a representative load: pprof.StartCPUProfile / curl .../debug/pprof/profile > default.pgo.
  2. Drop it at your main package root as default.pgo (picked up by go build automatically, i.e. -pgo=auto) or pass -pgo=/path/to.pprof.
  3. Rebuild and ship.

The committed benchmarks/bench-pgo.txt shows what the benchmark binary itself gains when rebuilt against its own profile (make bench-pgo): a −7.5% time geomean, with the arithmetic core improving the most because its outlined slow arms inline into the measured call sites. Three op families honestly regress where PGO's layout choices cost a little: every Cmp shape (+7% to +10%), the short Parse inputs (+2% to +5%), and NewFromFloat/typical_price (+2.5%) — the excerpt shows the worst such row:

                          │   default   │                 pgo                 │
                          │   sec/op    │   sec/op     vs base                │
Add/typical_price-10        2.375n ± 0%   2.022n ± 0%  -14.88% (p=0.000 n=10)
Sub/typical_price-10        3.743n ± 0%   3.119n ± 1%  -16.68% (p=0.000 n=10)
Mul/large-10                4.429n ± 1%   3.520n ± 0%  -20.52% (p=0.000 n=10)
Div/typical_price-10        11.70n ± 1%   10.24n ± 0%  -12.48% (p=0.000 n=10)
QuoRem/typical_price-10     3.155n ± 0%   2.651n ± 1%  -15.95% (p=0.000 n=10)
RoundBank/typical_price-10  4.677n ± 1%   3.730n ± 1%  -20.26% (p=0.000 n=10)
Cmp/typical_price-10        3.108n ± 2%   3.417n ± 0%   +9.96% (p=0.000 n=10)
geomean                     10.07n        9.313n        -7.50%

On amd64 deployments also consider GOAMD64=v3: the BMI2/ADX instructions materially speed the bits.Mul64/bits.Add64 carry chains that dominate the primitives (arm64 needs no flag).

Build tags

Tag Effect
zerodecimal_prec9 lowers the compile-time DefaultPrec to 9 fractional digits (nanos), trading fractional resolution for integer range in division results
zerodecimal_prec12 lowers DefaultPrec to 12, matching alpacadecimal's fixed scale
zerodecimal_nostrcache compiles out the ~8 MB small-value string/driver.Value cache (−1000.00..+1000.00) built at init

DefaultPrec is a compile-time constant by design — never a mutable global — so precision checks fold into immediate compares.

The full test suites assume DefaultPrec = 19. Compile + go vet is the supported verification level for the zerodecimal_prec9 and zerodecimal_prec12 configurations in v1.

How correctness is enforced

  • Deterministic cross-check in the default suite (crosscheck_test.go): every arithmetic, comparison, rounding, parsing, and formatting result is checked against shopspring/decimal's unbounded big.Int arithmetic over an exhaustive boundary-value pair sweep plus 30,000 fixed-seed boundary-biased random pairs. The overflow oracle is iff: every ErrOverflow must be proven exact (the true coefficient really is ≥ 2^128) and every fitting result must be returned — a spurious error fails as loudly as a wrong value.
  • 23 differential fuzz targets (fuzz_test.go, make fuzz-all): parse round trips and raw-string parsing, Add/Sub/Mul/Div/ QuoRem/Mod/Cmp with the same iff overflow proofs, all seven rounding modes pinned to their shopspring equivalents, StringFixed, JSON/binary/SQL round trips, garbage binary input (which must never panic), float conversion, and a structural-invariant target. quagmt/udecimal serves as a second, bit-compatible oracle for Add/Sub/Mul.
  • 6.5+ million fixed-seed primitive cases: the u128/u256 primitives and every reciprocal-division path are verified against bits.Div64 and big.Int at carry, limb, power-of-ten, and exact-overflow boundaries plus millions of shaped random cases per run (u128_test.go, u256_test.go, div10_test.go — the loop counts sum past 6.5 million), and the generated magic-constant tables are recomputed from their definitions in tables_test.go.
  • Codegen gates: the inlining shape of the hot paths (what must inline, what must stay outlined, cost ceilings against compiler drift) is asserted from the compiler's own -m=2 report in the default suite.

Limitations vs shopspring/decimal

  • Bounded domain. |value| < 2^128 / 10^prec — at most 39 significant digits and 19 fractional digits. There is no arbitrary-precision fallback; out-of-domain results return ErrOverflow. shopspring is unbounded.
  • places is uint8. Negative places (rounding at tens/hundreds positions, shopspring's Round(-2)) are unsupported by design — this is what keeps the entire rounding family infallible.
  • Division precision is compile-time. Div truncates at adaptive precision up to DefaultPrec (19, or 9/12 via build tags); there is no runtime DivisionPrecision knob and no DivRound.
  • No Pow, Sqrt, or transcendental functions yet.
  • Stricter parsing. "1." and ".1" are rejected; shopspring accepts both.
  • No exotic float forms. NewFromFloat rejects NaN/±Inf with ErrInvalidFloat rather than panicking, and converts via the shortest decimal representation (like shopspring) — floats outside the domain error instead of rounding silently.

License

MIT