Skip to content

Tags: aytechnet/decimal

Tags

v1.0.2

Toggle v1.0.2's commit message
fix godoc nits flagged by Go Report Card / staticcheck

- Add a package doc comment (ST1000)
- Fix the "Min returns the largest" copy-paste over func Max (ST1020)
- Re-order the StringFixedBank / StringFixedCash doc blocks so each comment is
  attached to the right function (StringFixedBank previously had its doc
  glued to StringFixedCash with no blank separator, and StringFixedBank had no
  doc at all)
- Fix the "MarshalJSON implements ..." copy-paste above func MarshalBinary
- Drop an extra blank line in core.go that broke gofmt

No behavioural change. Tests still 100% covered.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

v1.0.1

Toggle v1.0.1's commit message
add v2 binary extension format and Weight/Length MarshalBinary

The v1 binary format (1-byte header + optional uvarint mantissa) only covers
Decimal values within MaxInt mantissa and ±15 exponent. Two needs not addressed
by v1:
- Weight and Length had no MarshalBinary / UnmarshalBinary at all.
- A wider decimal type (e.g. coming from another implementation with bigger
  precision) had no way to round-trip through this package.

v2 hybridizes with v1: when the data fits in v1 (default unit for Weight/Length,
mantissa ≤ MaxInt, exp ∈ [-16,15]) the v1 byte stream is reused unchanged, so
"Decimal 5", "Weight 5kg" and "Length 5m" all serialize to the same `01 05`.
Otherwise an extension opcode is emitted, encoding sign(m), sign(exp), loss
flag, and a type marker (±2 = Decimal, ±4 = Weight, ±6 = Length) into the
v1 header byte's existing fields, followed by uvarint(unit) (Weight/Length only),
uvarint(|exp|), uvarint(|m|).

The 24 extension opcodes occupy bit patterns that v1 was using for redundant
NaN encodings; v2 fixes NaN to canonical 0x42 / 0xC2 and reuses the rest.
Single-byte streams keep the v1 magic-byte semantics for backward compatibility.

Cross-type reading (Option A): Decimal accepts any of the three families and
returns the bare m × 10^exp scalar, dropping any unit. Weight accepts v1 and
Decimal v2 (assuming kg), refuses Length v2 with ErrFormat. Length is symmetric.

Format is documented in BINARY_FORMAT.md (header layout, opcode tables, unit
tables, cross-type matrix, test vectors). README.md and CLAUDE.md updated to
link to the spec.

Test coverage: 100% maintained; new tests cover round-trip, cross-type interop,
cross-type refusal, magic-value reads, extension encoding branches (±sign,
±exp, ±loss), invalid/truncated streams, and out-of-range unit codes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

v1.0.0

Toggle v1.0.0's commit message
satisfy golangci-lint

CI's golangci-lint job flagged 4 issues:
- 3× errcheck on bench loops calling NewFromString / strconv.ParseInt /
  strconv.ParseFloat — discarded return values are intentional there. Drop
  them to `_, _ = ...` and exclude future occurrences in benchmarks via
  .golangci.yml.
- staticcheck SA9004 on the (sign uint64 / loss untyped) pair in core.go
  — the asymmetry is load-bearing: `sign` is typed so masks like
  `uint64(...) & sign` compile, while `loss` stays untyped so it composes
  with Decimal/Weight/Length operands without an explicit cast at each of
  ~40 call sites. Disable that one check in .golangci.yml.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

v0.9.0

Toggle v0.9.0's commit message
updated README

v0.6.0

Toggle v0.6.0's commit message
fix CI: drop TestLength and CLAUDE.md mention of length.go

length.go is a WIP placeholder kept untracked locally; it is not on main and
not referenced from the public API. Removing the test that depended on it so
CI can build cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

v0.5.0

Toggle v0.5.0's commit message
0.5.0

v0.3.0

Toggle v0.3.0's commit message
0.3.0

v0.2.1

Toggle v0.2.1's commit message
fixed weight conversion + simplified weight add + added more tests

v0.2.0

Toggle v0.2.0's commit message
improved decimal parsing + added unit support + introduced weight

v0.1.0

Toggle v0.1.0's commit message
added missing gofmt