1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Decimal comparison policy — the per-`(N, M, S1, S2)` algorithm matcher
//! for `PartialOrd<D<Int<M>, S2>> for D<Int<N>, S1>` and `Ord for
//! D<Int<N>, S>`.
//!
//! See `docs/ARCHITECTURE.md` → "Policy file structure".
//!
//! `D<Int<N>, S1>` comparison delegates to [`dcmp_dispatch`], which
//! follows the canonical policy shape:
//!
//! 1. an [`Algorithm`] enum — the real comparison algorithms, no `Default`
//! variant;
//! 2. a [`Select`] verdict — a settled algorithm or "the value decides"
//! (comparison choice is fully determined by the const generics, so
//! `ByValue` is never returned);
//! 3. a `const fn` [`select`] keyed on `(S1, S2)`, total over the key;
//! 4. dispatch via an inline `const { select::<N, S1, S2>() }` block, then
//! an **exhaustive** `match algo` — no `_`, no panic.
//!
//! Because `select` is `const` and keyed only on the const generics, the
//! `const { … }` block folds per monomorphisation and every unchosen arm
//! is dead-arm-eliminated in release: each concrete `(N, S1, S2)` compiles
//! to a direct call to one kernel, no runtime branch.
//!
//! # Why two algorithms
//!
//! When `S1 == S2` the operands share the same scale, so no cross-scale
//! multiply is needed — the comparison is a plain cross-width integer
//! compare (`cmp_cross_same_scale`). When `S1 != S2` the logical values
//! `a/10^S1` and `b/10^S2` have different denominators; the higher-scale
//! (more decimal digits) operand is compared against the lower-scale
//! operand scaled by `10^|S1−S2|` via the `Int` cross-scale comparator
//! (`cmp_cross_scaled_diff`). The `S1 == S2` branch is const-foldable
//! and collapses to a plain int compare in the common same-scale case.
//!
//! # Naming collision avoidance
//!
//! The integer policy module `src/int/policy/` contains `cmp` and `eq`
//! policies for the `Int<N>` type. This file is `dcmp` (decimal cmp) in
//! `src/policy/` to avoid any name collision with those int-tier modules.
use crateInt;
// ── 1. the real comparison algorithms — NAMED, no `Default` ──────────
/// The comparison algorithms this policy chooses between. Variants are the
/// CamelCase of each kernel name minus the `cmp_cross_` prefix, strict 1:1
/// with the kernel functions.
// ── 2. the const verdict ──────────────────────────────────────────────
/// A settled algorithm, or "the value decides". The comparison picker always
/// returns `ByAlgorithm`: the choice is fully determined by the const scales.
/// `ByValue` is part of the canonical shape for uniformity; `select` never
/// returns it.
// ── 3. the matcher: const, keyed on `(S1, S2)`, total over the key ───
/// Pick the comparison algorithm for decimal scales `S1` and `S2` with
/// storage limb count `N`. Total over the key:
/// - `S1 == S2` → `SameScale` (plain cross-width int compare);
/// - `S1 != S2` → `ScaledDiff` (cross-scale multiply-compare).
///
/// The `S1 == S2` branch const-folds away in the common same-scale case —
/// the monomorphisation sees only `SameScale` and the dead `ScaledDiff` arm
/// is eliminated in release.
const
// ── algorithm kernels ─────────────────────────────────────────────────
/// Cross-width same-scale comparison: delegates to `Int::cmp_cross`.
const
/// Cross-width cross-scale comparison. `a` has scale `S1`, `b` has `S2`.
/// Logical values are `a/10^S1` and `b/10^S2`. Scales to the lower operand's
/// denominator (dividing the higher-scale storage) so the comparison is
/// overflow-free and uses only `Int::cmp_cross_scaled`.
const
// ── 4. the dispatcher: fold the verdict, then dispatch ────────────────
/// Decimal comparison dispatcher for storage `Int<N>` / `Int<M>`, scales
/// `S1` / `S2`. Const-folds to a direct call to one kernel per
/// monomorphisation.
///
/// `const fn`: both kernels are `const fn` (they delegate to `Int`'s const
/// comparison primitives), so the dispatcher is also `const fn`.
pub const