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
//! Bespoke narrow-`GUARD` `sinh_strict` / `cosh_strict` /
//! `tanh_strict` kernel slot for `D57<SCALE>` with `SCALE ∈ 18..=22`.
//!
//! sinh / cosh / tanh all share the pair `(eˣ, e⁻ˣ)`. The
//! macro-emitted inherent path runs each `exp_fixed` at
//! `GUARD = 30`. At `SCALE ∈ 18..=22` the same narrow-GUARD trick
//! as [`crate::algos::exp::lookup_d57_s18_22`] applies — the
//! 12-LSB-of-w drift budget holds across the Taylor series at
//! `w = SCALE + 12 = 30..34` with many orders of magnitude margin.
//!
//! Per-call working width drops from `SCALE + 30 = 48..52` to
//! `SCALE + 12 = 30..34` — roughly two-thirds of the bits. Since
//! sinh / cosh do *two* `exp_fixed` calls per surface call, the
//! reclaim multiplies.
//!
//! ## Algorithm
//!
//! ```text
//! ex = exp(v)
//! enx = 1 / ex (exp(-v) identity)
//! sinh = (ex - enx) / 2
//! cosh = (ex + enx) / 2
//! tanh = (ex - enx) / (ex + enx)
//! ```
//!
//! Same shape as the macro-emitted inherent methods, but the second
//! `exp_fixed(-v, w)` is replaced by a single wide divide — wide-tier
//! `exp_fixed` is dominated by the Tang-table reduction + Taylor
//! series and costs ~10-20× more than a wide divide, so the identity
//! drops per-call wall-clock ~40%.
//!
//! ## Correctness
//!
//! Error budget at working scale `w = SCALE + 8` (in LSB-of-w):
//!
//! - One `exp_fixed` call: ≤ 12 LSB (worst-case Taylor drift).
//! - One `1/ex` divide (rounded half-to-even): ≤ 0.5 LSB.
//! - One add (cosh) or sub (sinh): ≤ 1 LSB.
//! - One divide-by-2 (cosh / sinh): ≤ 0.5 LSB.
//! - Final round-to-storage: ≤ 0.5 LSB.
//!
//! Total ≤ ~15 LSB-of-w = ~15·10⁻⁸ in storage units — many orders of
//! magnitude below half a storage ULP for any SCALE ≤ 22.
use cratewide_trig_d57 as core;
use crateRoundingMode;
use crateInt192;
/// Narrow guard for the SCALE 18..=22 hyperbolic slot. Matches the
/// exp / ln narrow guard so a sinh/cosh call shares the same `pow10_w`
/// cache slot with neighboring exp / ln invocations.
const GUARD_NARROW: u32 = 8;
/// Joint `(ex, enx)` pair shared by sinh / cosh / tanh. One Tang exp
/// call yields `eˣ`, and `e⁻ˣ = 1/eˣ` follows from one wide divide —
/// versus a second `exp_fixed` call that's an order of magnitude
/// more expensive.
/// `sinh_strict` for `D57<SCALE>` with `SCALE ∈ 18..=22`. One Tang
/// `exp` + one reciprocal-divide for the `(eˣ, e⁻ˣ)` pair.
pub
/// `cosh_strict` for `D57<SCALE>` with `SCALE ∈ 18..=22`.
pub
/// `tanh_strict` for `D57<SCALE>` with `SCALE ∈ 18..=22`.
pub