Skip to main content

devela/num/dom/real/float/wrapper/
definition.rs

1// devela::num::dom::real::float::wrapper::definition
2//
3//! Defines [`Float`].
4//
5// TODO: Write doc with methods in a separate constant.
6
7#[doc = crate::_tags!(num namespace optional_std)]
8/// Provides comprehensive floating-point operations for `T`, most of them *const*.
9#[doc = crate::_doc_meta!{location("num/dom/real")}]
10///
11/// See also the [`FloatConst`][crate::FloatConst] and [`FloatExt`] traits.
12#[doc = crate::doclink!(custom devela "[`FloatExt`]" "num/trait.FloatExt.html")]
13///
14// # Methods
15// TODO
16///
17/// The wrapper leverages `std` if enabled, otherwise implements fallbacks.
18/// It also favors `std` style for method's names, but changes a few like `minimum`
19/// for `min_nan` and `maximum` for `max_nan`, for consistency.
20#[must_use]
21#[repr(transparent)]
22pub struct Float<T>(pub T);
23
24crate::_num_dom_impl_arith![Float: f32, f64];
25#[cfg(nightly_float)]
26crate::_num_dom_impl_arith![Float: f16, f128];
27
28#[rustfmt::skip]
29mod core_impls {
30    use super::Float;
31    use crate::{ConstInit, Debug, Display, FmtResult, Formatter, Ordering};
32
33    impl<T: ConstInit> ConstInit for Float<T> {
34        const INIT: Self = Float(T::INIT);
35    }
36
37    impl<T: Clone> Clone for Float<T> {
38        fn clone(&self) -> Self { Self(self.0.clone()) }
39    }
40    impl<T: Copy> Copy for Float<T> {}
41    impl<T: Debug> Debug for Float<T> {
42        fn fmt(&self, f: &mut Formatter) -> FmtResult<()> {
43            f.debug_tuple("Float").field(&self.0).finish()
44        }
45    }
46    impl<T: Display> Display for Float<T> {
47        fn fmt(&self, f: &mut Formatter) -> FmtResult<()> { Display::fmt(&self.0, f) }
48    }
49
50    impl<T: PartialEq> PartialEq for Float<T> {
51        fn eq(&self, other: &Self) -> bool { self.0.eq(&other.0) }
52    }
53    impl<T: PartialEq> PartialEq<T> for Float<T> {
54        fn eq(&self, other: &T) -> bool { self.0.eq(other) }
55    }
56
57    impl<T: PartialOrd> PartialOrd for Float<T> {
58        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
59            self.0.partial_cmp(&other.0)
60        }
61    }
62    impl<T: PartialOrd> PartialOrd<T> for Float<T> {
63        fn partial_cmp(&self, other: &T) -> Option<Ordering> {
64            self.0.partial_cmp(other)
65        }
66    }
67    // MAYBE
68    // impl<T> crate::Deref for Float<T> {
69    //     type Target = T;
70    //     fn deref(&self) -> &Self::Target { &self.0 }
71    // }
72    // impl<T> crate::DerefMut for Float<T> {
73    //     fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
74    // }
75}