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
//! Macro-generated strict-mode transcendentals for the narrow decimal
//! widths (D9 / D18), by delegation to the D38 strict path.
//!
//! For each method the input is widened to `D38<SCALE>`, the D38
//! `*_strict` implementation is called, and the result is narrowed
//! back. This gives D9 / D18 the full integer-only transcendental
//! surface (ln, log, log2, log10, exp, exp2, sqrt, cbrt, powf, and the
//! trig / hyperbolic / angle family) without duplicating the
//! algorithmic work. The narrowing step panics if the result exceeds
//! the target storage's range.
//!
//! Two surfaces are emitted per method, mirroring the D38 layout:
//!
//! - `<method>_strict` — always present unless the `fast` feature
//! is set. Integer-only; `no_std`-compatible.
//! - `<method>` — a dispatcher present only under
//! `#[cfg(all(feature = "strict", not(feature = "fast")))]`,
//! forwarding to `<method>_strict`. (D9 / D18 have no f64-bridge
//! transcendentals of their own, so there is no non-strict `<method>`
//! for these widths.)
/// Emits the strict-mode transcendental surface for `$Type<SCALE>` by
/// delegating to the D38 `*_strict` implementations.
macro_rules! decl_strict_transcendentals_via_d38 {
($Type:ident) => {
impl<const SCALE: u32> $Type<SCALE> {
/// `ln_strict` — delegates to [`crate::core_type::D38::ln_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn ln_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.ln_strict())
.expect(concat!(stringify!($Type), "::ln_strict: result out of range"))
}
/// `log2_strict` — delegates to [`crate::core_type::D38::log2_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn log2_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.log2_strict())
.expect(concat!(stringify!($Type), "::log2_strict: result out of range"))
}
/// `log10_strict` — delegates to [`crate::core_type::D38::log10_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn log10_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.log10_strict())
.expect(concat!(stringify!($Type), "::log10_strict: result out of range"))
}
/// `exp_strict` — delegates to [`crate::core_type::D38::exp_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn exp_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.exp_strict())
.expect(concat!(stringify!($Type), "::exp_strict: result out of range"))
}
/// `exp2_strict` — delegates to [`crate::core_type::D38::exp2_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn exp2_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.exp2_strict())
.expect(concat!(stringify!($Type), "::exp2_strict: result out of range"))
}
/// `sqrt_strict` — delegates to [`crate::core_type::D38::sqrt_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn sqrt_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.sqrt_strict())
.expect(concat!(stringify!($Type), "::sqrt_strict: result out of range"))
}
/// `cbrt_strict` — delegates to [`crate::core_type::D38::cbrt_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn cbrt_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.cbrt_strict())
.expect(concat!(stringify!($Type), "::cbrt_strict: result out of range"))
}
/// `sin_strict` — delegates to [`crate::core_type::D38::sin_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn sin_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.sin_strict())
.expect(concat!(stringify!($Type), "::sin_strict: result out of range"))
}
/// `cos_strict` — delegates to [`crate::core_type::D38::cos_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn cos_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.cos_strict())
.expect(concat!(stringify!($Type), "::cos_strict: result out of range"))
}
/// `tan_strict` — delegates to [`crate::core_type::D38::tan_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn tan_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.tan_strict())
.expect(concat!(stringify!($Type), "::tan_strict: result out of range"))
}
/// `asin_strict` — delegates to [`crate::core_type::D38::asin_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn asin_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.asin_strict())
.expect(concat!(stringify!($Type), "::asin_strict: result out of range"))
}
/// `acos_strict` — delegates to [`crate::core_type::D38::acos_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn acos_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.acos_strict())
.expect(concat!(stringify!($Type), "::acos_strict: result out of range"))
}
/// `atan_strict` — delegates to [`crate::core_type::D38::atan_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn atan_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.atan_strict())
.expect(concat!(stringify!($Type), "::atan_strict: result out of range"))
}
/// `sinh_strict` — delegates to [`crate::core_type::D38::sinh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn sinh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.sinh_strict())
.expect(concat!(stringify!($Type), "::sinh_strict: result out of range"))
}
/// `cosh_strict` — delegates to [`crate::core_type::D38::cosh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn cosh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.cosh_strict())
.expect(concat!(stringify!($Type), "::cosh_strict: result out of range"))
}
/// `tanh_strict` — delegates to [`crate::core_type::D38::tanh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn tanh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.tanh_strict())
.expect(concat!(stringify!($Type), "::tanh_strict: result out of range"))
}
/// `asinh_strict` — delegates to [`crate::core_type::D38::asinh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn asinh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.asinh_strict())
.expect(concat!(stringify!($Type), "::asinh_strict: result out of range"))
}
/// `acosh_strict` — delegates to [`crate::core_type::D38::acosh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn acosh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.acosh_strict())
.expect(concat!(stringify!($Type), "::acosh_strict: result out of range"))
}
/// `atanh_strict` — delegates to [`crate::core_type::D38::atanh_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn atanh_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.atanh_strict())
.expect(concat!(stringify!($Type), "::atanh_strict: result out of range"))
}
/// `to_degrees_strict` — delegates to [`crate::core_type::D38::to_degrees_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn to_degrees_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.to_degrees_strict())
.expect(concat!(stringify!($Type), "::to_degrees_strict: result out of range"))
}
/// `to_radians_strict` — delegates to [`crate::core_type::D38::to_radians_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn to_radians_strict(self) -> Self {
let wide: $crate::core_type::D38<SCALE> = self.into();
::core::convert::TryInto::try_into(wide.to_radians_strict())
.expect(concat!(stringify!($Type), "::to_radians_strict: result out of range"))
}
/// `log_strict` — delegates to [`crate::core_type::D38::log_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn log_strict(self, base: Self) -> Self {
let wide_self: $crate::core_type::D38<SCALE> = self.into();
let wide_base: $crate::core_type::D38<SCALE> = base.into();
::core::convert::TryInto::try_into(wide_self.log_strict(wide_base))
.expect(concat!(stringify!($Type), "::log_strict: result out of range"))
}
/// `atan2_strict` — delegates to [`crate::core_type::D38::atan2_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn atan2_strict(self, other: Self) -> Self {
let wide_self: $crate::core_type::D38<SCALE> = self.into();
let wide_other: $crate::core_type::D38<SCALE> = other.into();
::core::convert::TryInto::try_into(wide_self.atan2_strict(wide_other))
.expect(concat!(stringify!($Type), "::atan2_strict: result out of range"))
}
/// `powf_strict` — delegates to [`crate::core_type::D38::powf_strict`] via widen → strict → narrow. **0.5 ULP correctly-rounded** at storage scale. Panics if the result doesn't fit `Self`'s range.
#[inline]
#[must_use]
pub fn powf_strict(self, exp: Self) -> Self {
let wide_self: $crate::core_type::D38<SCALE> = self.into();
let wide_exp: $crate::core_type::D38<SCALE> = exp.into();
::core::convert::TryInto::try_into(wide_self.powf_strict(wide_exp))
.expect(concat!(stringify!($Type), "::powf_strict: result out of range"))
}
/// `ln` — feature-gated dispatcher; forwards to [`Self::ln_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn ln(self) -> Self {
self.ln_strict()
}
/// `log2` — feature-gated dispatcher; forwards to [`Self::log2_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn log2(self) -> Self {
self.log2_strict()
}
/// `log10` — feature-gated dispatcher; forwards to [`Self::log10_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn log10(self) -> Self {
self.log10_strict()
}
/// `exp` — feature-gated dispatcher; forwards to [`Self::exp_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn exp(self) -> Self {
self.exp_strict()
}
/// `exp2` — feature-gated dispatcher; forwards to [`Self::exp2_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn exp2(self) -> Self {
self.exp2_strict()
}
/// `sqrt` — feature-gated dispatcher; forwards to [`Self::sqrt_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn sqrt(self) -> Self {
self.sqrt_strict()
}
/// `cbrt` — feature-gated dispatcher; forwards to [`Self::cbrt_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn cbrt(self) -> Self {
self.cbrt_strict()
}
/// `sin` — feature-gated dispatcher; forwards to [`Self::sin_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn sin(self) -> Self {
self.sin_strict()
}
/// `cos` — feature-gated dispatcher; forwards to [`Self::cos_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn cos(self) -> Self {
self.cos_strict()
}
/// `tan` — feature-gated dispatcher; forwards to [`Self::tan_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn tan(self) -> Self {
self.tan_strict()
}
/// `asin` — feature-gated dispatcher; forwards to [`Self::asin_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn asin(self) -> Self {
self.asin_strict()
}
/// `acos` — feature-gated dispatcher; forwards to [`Self::acos_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn acos(self) -> Self {
self.acos_strict()
}
/// `atan` — feature-gated dispatcher; forwards to [`Self::atan_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn atan(self) -> Self {
self.atan_strict()
}
/// `sinh` — feature-gated dispatcher; forwards to [`Self::sinh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn sinh(self) -> Self {
self.sinh_strict()
}
/// `cosh` — feature-gated dispatcher; forwards to [`Self::cosh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn cosh(self) -> Self {
self.cosh_strict()
}
/// `tanh` — feature-gated dispatcher; forwards to [`Self::tanh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn tanh(self) -> Self {
self.tanh_strict()
}
/// `asinh` — feature-gated dispatcher; forwards to [`Self::asinh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn asinh(self) -> Self {
self.asinh_strict()
}
/// `acosh` — feature-gated dispatcher; forwards to [`Self::acosh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn acosh(self) -> Self {
self.acosh_strict()
}
/// `atanh` — feature-gated dispatcher; forwards to [`Self::atanh_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn atanh(self) -> Self {
self.atanh_strict()
}
/// `to_degrees` — feature-gated dispatcher; forwards to [`Self::to_degrees_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn to_degrees(self) -> Self {
self.to_degrees_strict()
}
/// `to_radians` — feature-gated dispatcher; forwards to [`Self::to_radians_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn to_radians(self) -> Self {
self.to_radians_strict()
}
/// `log` — feature-gated dispatcher; forwards to [`Self::log_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn log(self, base: Self) -> Self {
self.log_strict(base)
}
/// `atan2` — feature-gated dispatcher; forwards to [`Self::atan2_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn atan2(self, other: Self) -> Self {
self.atan2_strict(other)
}
/// `powf` — feature-gated dispatcher; forwards to [`Self::powf_strict`] when the `strict` feature is on.
#[cfg(all(feature = "strict", not(feature = "fast")))]
#[inline]
#[must_use]
pub fn powf(self, exp: Self) -> Self {
self.powf_strict(exp)
}
}
};
}
pub(crate) use decl_strict_transcendentals_via_d38;