devela/num/float/wrapper/
mod.rs

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