# shopspring/decimal architecture

> Architecture diagram of the GitHub repository shopspring/decimal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shopspring/decimal
- Repository: https://github.com/shopspring/decimal

## Overview

This is a Go library for arbitrary-precision fixed-point decimals. A caller constructs or parses Decimal values, performs exact basic arithmetic or precision-controlled division (and optional advanced math), then formats or serializes the result. The implementation is a compact package rather than a service: its main layers are the Decimal API, mathematical operations, and encoding support. The README documents the workflow and serialization capabilities; some internal implementation relationships are omitted because the excerpts do not show their call sites.

Main entry points: [`decimal.go`](https://github.com/shopspring/decimal/blob/master/decimal.go) (Decimal API), [`math.go`](https://github.com/shopspring/decimal/blob/master/math.go) (Advanced math), [`encoding.go`](https://github.com/shopspring/decimal/blob/master/encoding.go) (Encoding adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_decimal["Decimal values"]
  node_decimal_api["Decimal API<br/>[decimal.go]"]
  node_float_format["Float formatting<br/>[decimal-go.go]"]
  node_rounding["Float rounding<br/>[rounding.go]"]
end

subgraph group_math["Math operations"]
  node_math_ops["Advanced math<br/>[math.go]"]
  node_math_constants["Math constants<br/>[const.go]"]
end

subgraph group_encoding["Serialization"]
  node_encoders["Encoding adapters<br/>[encoding.go]"]
end

node_caller(("Go caller"))

node_caller -->|"constructs and calculates"| node_decimal_api
node_caller -->|"uses advanced math"| node_math_ops
node_caller -->|"serializes values"| node_encoders

click node_decimal_api "https://github.com/shopspring/decimal/blob/master/decimal.go"
click node_float_format "https://github.com/shopspring/decimal/blob/master/decimal-go.go"
click node_rounding "https://github.com/shopspring/decimal/blob/master/rounding.go"
click node_math_ops "https://github.com/shopspring/decimal/blob/master/math.go"
click node_math_constants "https://github.com/shopspring/decimal/blob/master/const.go"
click node_encoders "https://github.com/shopspring/decimal/blob/master/encoding.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_decimal_api,node_float_format,node_rounding toneBlue
class node_math_ops,node_math_constants toneAmber
class node_encoders toneMint
class node_caller toneIndigo
```

## Components

### Decimal values

- [Decimal API](https://github.com/shopspring/decimal/blob/master/decimal.go): `decimal.go`
- [Float formatting](https://github.com/shopspring/decimal/blob/master/decimal-go.go): `decimal-go.go`
- [Float rounding](https://github.com/shopspring/decimal/blob/master/rounding.go): `rounding.go`

### Math operations

- [Advanced math](https://github.com/shopspring/decimal/blob/master/math.go): `math.go`
- [Math constants](https://github.com/shopspring/decimal/blob/master/const.go): `const.go`

### Serialization

- [Encoding adapters](https://github.com/shopspring/decimal/blob/master/encoding.go): `encoding.go`

### Other components

- **Go caller**

## Connections

- Go caller → Decimal API: constructs and calculates (evidence: `README.md`)
- Go caller → Advanced math: uses advanced math (evidence: `README.md`)
- Go caller → Encoding adapters: serializes values (evidence: `README.md`)
