devela/num/float/wrapper/mod.rs
1// devela::num::float::wrapper
2//
3//! Floating-point wrapper struct.
4//
5
6mod consts; // ExtFloatConst
7
8// WIPZONE
9// mod namespace; // Float
10
11#[cfg(all(test, feature = "_float_f32"))]
12mod tests_f32;
13
14#[cfg(_float··)]
15crate::items! {
16 mod libm_std; // for either or neither.
17 mod shared; // implements shared methods.
18 mod shared_series; // with Taylor Series.
19}
20
21#[doc = crate::TAG_NAMESPACE!()]
22/// Provides comprehensive floating-point operations for `T`, most of them *const*.
23///
24/// See also the [`ExtFloat`][super::ExtFloat] and [`ExtFloatConst`][super::ExtFloatConst] traits.
25///
26/// # Methods
27/// TODO
28///
29/// # Features
30/// It depends on having any `_float_f[32|64]` features enabled.
31///
32/// The wrapper leverages `std` or `libm` if enabled, otherwise implements fallbacks.
33/// It also favors `std` style for method's names, but changes a few like `minimum`
34/// for `min_nan` and `maximum` for `max_nan`, for consistency.
35///
36/// If both the `libm` and `std` features are enabled the `libm` functions will
37/// be used, since it contains more functions, namely:
38/// - Gamma functions: [`gamma`][Float#method.gamma], [`lgamma`][Float#method.lgamma],
39/// [`lgamma_r`][Float#method.lgamma_r].
40/// - Bessel functions:
41/// [`j0`][Float#method.j0], [`j1`][Float#method.j1], [`jn`][Float#method.jn],
42/// [`y0`][Float#method.y0], [`y1`][Float#method.y1], [`yn`][Float#method.yn].
43/// - Error functions: [`erf`][Float#method.erf], [`erfc`][Float#method.erfc].
44/// - [`exp10`][Float#method.exp10].
45#[must_use]
46#[repr(transparent)]
47pub struct Float<T>(pub T);
48
49crate::num::impl_ops![Float: f32:"_float_f32", f64:"_float_f64"];
50// #[cfg(feature = "nightly_float")]
51// crate::num::impl_ops![Float: f16:"_float_f16", f128:"_float_f128"];
52
53#[rustfmt::skip]
54mod core_impls {
55 use crate::{_core::fmt, Float, Ordering};
56
57 impl<T: Clone> Clone for Float<T> {
58 fn clone(&self) -> Self { Self(self.0.clone()) }
59 }
60 impl<T: Copy> Copy for Float<T> {}
61 impl<T: fmt::Debug> fmt::Debug for Float<T> {
62 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63 f.debug_tuple("Float").field(&self.0).finish()
64 }
65 }
66 impl<T: fmt::Display> fmt::Display for Float<T> {
67 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
68 }
69
70 impl<T: PartialEq> PartialEq for Float<T> {
71 fn eq(&self, other: &Self) -> bool { self.0.eq(&other.0) }
72 }
73 impl<T: PartialEq> PartialEq<T> for Float<T> {
74 fn eq(&self, other: &T) -> bool { self.0.eq(other) }
75 }
76
77 impl<T: PartialOrd> PartialOrd for Float<T> {
78 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
79 self.0.partial_cmp(&other.0)
80 }
81 }
82 impl<T: PartialOrd> PartialOrd<T> for Float<T> {
83 fn partial_cmp(&self, other: &T) -> Option<Ordering> {
84 self.0.partial_cmp(other)
85 }
86 }
87}