decimal-scaled 0.4.2

Const-generic base-10 fixed-point decimals (D9/D18/D38/D76/D153/D307) with integer-only transcendentals correctly rounded to within 0.5 ULP — exact at the type's last representable place. Deterministic across every platform; no_std-friendly.
Documentation
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
//! Natural-logarithm policy (plus `log` / `log2` / `log10`).
//!
//! Narrow tier (D9 / D18 / D38) routes the `Fixed` 256-bit
//! intermediate kernels; wide tier (D57 .. D1232) routes the per-tier
//! kernels in [`crate::algos::ln::wide_kernel`] that wrap each tier's
//! macro-emitted `wide_trig_<tier>::ln_fixed` core. The wide-tier
//! macro does not ship a runtime-`working_digits` variant of
//! `ln_fixed`, so the wide-tier `_with_impl` methods ignore the
//! caller-supplied digits and fall through to the strict path. This
//! trade-off keeps `*_approx_with` / `*_with` working on wide tiers
//! (correct but no faster than `*_strict_with`); promoting it to a
//! true runtime-guard kernel is a follow-up.
//!
//! The trait carries the four-variant matrix as two methods per
//! function — `*_impl` (strict, const-folded working scale) and
//! `*_with_impl` (caller-chosen working digits) — each taking an
//! explicit rounding mode. The no-mode variants live in the typed
//! method shells and delegate here with
//! [`crate::support::rounding::DEFAULT_ROUNDING_MODE`].
//!
//! Functions covered: `ln`, `log` (variable base), `log2`, `log10`.

use crate::algos::ln;
use crate::types::widths::{D9, D18, D38};
use crate::support::rounding::RoundingMode;

/// Per-width policy for natural log and the log family. See module
/// docs.
pub(crate) trait LnPolicy: Sized {
    // ── Natural log ────────────────────────────────────────────────

    /// Strict natural log under the supplied rounding mode. Working
    /// scale is `SCALE + STRICT_GUARD` (const-folded).
    fn ln_impl(self, mode: RoundingMode) -> Self;

    /// Natural log with caller-chosen `working_digits` above the
    /// storage scale, under the supplied rounding mode.
    fn ln_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self;

    // ── Log with chosen base ───────────────────────────────────────

    /// `log_base(self)` under the supplied rounding mode (strict
    /// guard).
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self;

    /// `log_base(self)` with caller-chosen guard digits.
    fn log_with_impl(self, base: Self, working_digits: u32, mode: RoundingMode) -> Self;

    // ── Base-2 log ─────────────────────────────────────────────────

    fn log2_impl(self, mode: RoundingMode) -> Self;
    fn log2_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self;

    // ── Base-10 log ────────────────────────────────────────────────

    fn log10_impl(self, mode: RoundingMode) -> Self;
    fn log10_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self;
}

// ── Narrow tier — width override: widen → D38 ───────────────────────
//
// D9 / D18 widen into D38 for every log-family method; the narrow
// strict tests verify this widen-narrow path. `log` / `log2` / `log10`
// for D9 / D18 widen, call D38's method, then narrow back via
// `TryInto` — identical to the shape `decl_strict_transcendental!`
// already uses in the macro.

macro_rules! impl_log_widen {
    ($T:ident, $ln_strict:path, $ln_with:path) => {
        impl<const SCALE: u32> LnPolicy for $T<SCALE> {
            #[inline]
            fn ln_impl(self, mode: RoundingMode) -> Self {
                $ln_strict(self, mode)
            }
            #[inline]
            fn ln_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
                $ln_with(self, working_digits, mode)
            }
            #[inline]
            fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                let wbase: D38<SCALE> = base.into();
                ::core::convert::TryInto::try_into(wide.log_strict_with(wbase, mode))
                    .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                        concat!(stringify!($T), "::log"), SCALE,
                    ))
            }
            #[inline]
            fn log_with_impl(self, base: Self, working_digits: u32, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                let wbase: D38<SCALE> = base.into();
                ::core::convert::TryInto::try_into(
                    wide.log_approx_with(wbase, working_digits, mode),
                )
                .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                    concat!(stringify!($T), "::log"), SCALE,
                ))
            }
            #[inline]
            fn log2_impl(self, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                ::core::convert::TryInto::try_into(wide.log2_strict_with(mode))
                    .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                        concat!(stringify!($T), "::log2"), SCALE,
                    ))
            }
            #[inline]
            fn log2_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                ::core::convert::TryInto::try_into(wide.log2_approx_with(working_digits, mode))
                    .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                        concat!(stringify!($T), "::log2"), SCALE,
                    ))
            }
            #[inline]
            fn log10_impl(self, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                ::core::convert::TryInto::try_into(wide.log10_strict_with(mode))
                    .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                        concat!(stringify!($T), "::log10"), SCALE,
                    ))
            }
            #[inline]
            fn log10_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
                let wide: D38<SCALE> = self.into();
                ::core::convert::TryInto::try_into(wide.log10_approx_with(working_digits, mode))
                    .unwrap_or_else(|_| crate::support::diagnostics::overflow_panic_with_scale(
                        concat!(stringify!($T), "::log10"), SCALE,
                    ))
            }
        }
    };
}

impl_log_widen!(D9, ln::widen_to_d38::ln_strict_d9, ln::widen_to_d38::ln_with_d9);
impl_log_widen!(D18, ln::widen_to_d38::ln_strict_d18, ln::widen_to_d38::ln_with_d18);

// ── D38 — width override ───────────────────────────────────────────
//
// When D57 is available, D38's ln/log family routes through
// `borrow_d57` — widen to D57, call D57's wide_kernel, narrow back.
// The D57 kernel is 2-4× faster than D38's bespoke `Fixed` 256-bit
// path at matched precision. Without `d57` / `wide` the implementation
// falls back to the `Fixed` kernels in `algos::ln::fixed_d38`.
//
// `*_with_impl`: D57's wide_kernel has no runtime-`working_digits`
// variant, so the borrow path collapses to the strict kernel.

// D38 — use the in-tree `Fixed`-256 `ln_fixed` directly. See the
// `crate::policy::exp` comment for the same routing change rationale:
// once the MG-routed Fixed primitives ship the bespoke `Fixed`
// kernel beats the borrow_d57 round trip.
impl<const SCALE: u32> LnPolicy for D38<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::ln_strict::<SCALE>(self.0, mode))
    }
    #[inline]
    fn ln_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::ln_with(self.0, SCALE, working_digits, mode))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log_strict::<SCALE>(self.0, base.0, mode))
    }
    #[inline]
    fn log_with_impl(self, base: Self, working_digits: u32, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log_with(self.0, base.0, SCALE, working_digits, mode))
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log2_strict::<SCALE>(self.0, mode))
    }
    #[inline]
    fn log2_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log2_with(self.0, SCALE, working_digits, mode))
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log10_strict::<SCALE>(self.0, mode))
    }
    #[inline]
    fn log10_with_impl(self, working_digits: u32, mode: RoundingMode) -> Self {
        Self(ln::fixed_d38::log10_with(self.0, SCALE, working_digits, mode))
    }
}

// ── Wide tiers — width default ─────────────────────────────────────
//
// Wide tiers route `ln` through `wide_kernel::ln_strict_<tier>`; the
// log family methods (`log`, `log2`, `log10`) keep the inherent
// `*_strict_with` shells emitted by `decl_wide_transcendental!` since
// they compose `ln_fixed` / `ln2` / `ln10` from the per-tier core in a
// way that doesn't have a free-function equivalent in
// `algos::ln::wide_kernel` today. The `*_with_impl` collapses to
// strict; see module docs.
//
// `impl_wide_ln!` emits the cross-cutting `LnPolicy` impl: `ln_impl`
// via `wide_kernel`, the log family via the inherent shells.

macro_rules! impl_wide_ln {
    ($T:ident, $ln:path) => {
        impl<const SCALE: u32> LnPolicy for crate::types::widths::$T<SCALE> {
            #[inline]
            fn ln_impl(self, mode: RoundingMode) -> Self {
                Self($ln(self.0, mode, SCALE))
            }
            #[inline]
            fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
                Self($ln(self.0, mode, SCALE))
            }
            #[inline]
            fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
                self.log_strict_with(base, mode)
            }
            #[inline]
            fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
                self.log_strict_with(base, mode)
            }
            #[inline]
            fn log2_impl(self, mode: RoundingMode) -> Self {
                self.log2_strict_with(mode)
            }
            #[inline]
            fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
                self.log2_strict_with(mode)
            }
            #[inline]
            fn log10_impl(self, mode: RoundingMode) -> Self {
                self.log10_strict_with(mode)
            }
            #[inline]
            fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
                self.log10_strict_with(mode)
            }
        }
    };
}

// D57 — bespoke arm so `ln_impl` can divert SCALE ∈ 18..=22 through
// the narrow-GUARD lookup before falling back to `wide_kernel`.
#[cfg(any(feature = "d57", feature = "wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D57<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 18..=22) {
            return Self(ln::lookup_d57_s18_22_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d57(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 18..=22) {
            return Self(ln::lookup_d57_s18_22_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d57(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

#[cfg(any(feature = "d76", feature = "wide"))]
impl_wide_ln!(D76, ln::wide_kernel::ln_strict_d76);

// D115 — bespoke arm so `ln_impl` can divert SCALE = 57 through the
// Tang-style narrow-GUARD lookup before falling back to `wide_kernel`.
#[cfg(any(feature = "d115", feature = "wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D115<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 50..=60) {
            return Self(ln::lookup_d115_s57_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d115(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 50..=60) {
            return Self(ln::lookup_d115_s57_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d115(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

// D153 — bespoke arm so `ln_impl` can divert SCALE ∈ 70..=82 (the
// mid-storage band centred on SCALE = 76) through the Tang-style
// narrow-GUARD lookup before falling back to `wide_kernel`. See
// [`crate::algos::ln::lookup_d153_s70_82_tang`] for the algorithm.
#[cfg(any(feature = "d153", feature = "wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D153<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 70..=82) {
            return Self(ln::lookup_d153_s70_82_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d153(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 70..=82) {
            return Self(ln::lookup_d153_s70_82_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d153(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

#[cfg(any(feature = "d230", feature = "wide"))]
impl_wide_ln!(D230, ln::wide_kernel::ln_strict_d230);

// D307 — bespoke arm so `ln_impl` can divert SCALE ∈ 140..=160 (the
// popular mid-band centred on the half-MAX point) through the Tang-
// style narrow-GUARD lookup before falling back to `wide_kernel`. See
// [`crate::algos::ln::lookup_d307_s140_160_tang`] for the algorithm.
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D307<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 140..=160) {
            return Self(ln::lookup_d307_s140_160_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d307(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 140..=160) {
            return Self(ln::lookup_d307_s140_160_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d307(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

// D462 — bespoke arm so `ln_impl` can divert SCALE ∈ 225..=235 (the
// popular mid-storage band centred on `SCALE = 230 = MAX_SCALE / 2`)
// through the Tang-style narrow-GUARD lookup before falling back to
// `wide_kernel`. See [`crate::algos::ln::lookup_d462_s225_235_tang`].
#[cfg(any(feature = "d462", feature = "x-wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D462<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 225..=235) {
            return Self(ln::lookup_d462_s225_235_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d462(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 225..=235) {
            return Self(ln::lookup_d462_s225_235_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d462(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

// D616 — bespoke arm so `ln_impl` can divert SCALE ∈ 300..=315 (the
// mid-storage band centred on SCALE = 308) through the Tang-style
// narrow-GUARD lookup before falling back to `wide_kernel`. See
// [`crate::algos::ln::lookup_d616_s300_315_tang`] for the algorithm.
#[cfg(any(feature = "d616", feature = "x-wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D616<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 300..=315) {
            return Self(ln::lookup_d616_s300_315_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d616(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 300..=315) {
            return Self(ln::lookup_d616_s300_315_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d616(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

// D924 — bespoke arm so `ln_impl` can divert SCALE ∈ 455..=465 (the
// popular mid-storage band centred on `SCALE = 461 ≈ MAX_SCALE / 2`)
// through the Tang-style narrow-GUARD lookup before falling back to
// `wide_kernel`. See [`crate::algos::ln::lookup_d924_s455_465_tang`].
#[cfg(any(feature = "d924", feature = "xx-wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D924<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 455..=465) {
            return Self(ln::lookup_d924_s455_465_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d924(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 455..=465) {
            return Self(ln::lookup_d924_s455_465_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d924(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}

// D1232 — bespoke arm so `ln_impl` can divert SCALE ∈ 610..=620 (the
// mid-storage band centred on SCALE = 615) through the Tang-style
// narrow-GUARD lookup before falling back to `wide_kernel`. See
// [`crate::algos::ln::lookup_d1232_s610_620_tang`] for the algorithm.
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
impl<const SCALE: u32> LnPolicy for crate::types::widths::D1232<SCALE> {
    #[inline]
    fn ln_impl(self, mode: RoundingMode) -> Self {
        if matches!(SCALE, 610..=620) {
            return Self(ln::lookup_d1232_s610_620_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d1232(self.0, mode, SCALE))
    }
    #[inline]
    fn ln_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        if matches!(SCALE, 610..=620) {
            return Self(ln::lookup_d1232_s610_620_tang::ln_strict::<SCALE>(self.0, mode));
        }
        Self(ln::wide_kernel::ln_strict_d1232(self.0, mode, SCALE))
    }
    #[inline]
    fn log_impl(self, base: Self, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log_with_impl(self, base: Self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log_strict_with(base, mode)
    }
    #[inline]
    fn log2_impl(self, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log2_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log2_strict_with(mode)
    }
    #[inline]
    fn log10_impl(self, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
    #[inline]
    fn log10_with_impl(self, _working_digits: u32, mode: RoundingMode) -> Self {
        self.log10_strict_with(mode)
    }
}