base_traits/traits/
is_nan.rs

1// src/traits/is_nan.rs : `IsNAN`
2
3/// Trait defining instance method `is_nan() : bool` that indicates
4/// whether the implementing type instance has a value that is deemed to be
5/// "not a number" (as in so for [`f32::NAN`] [`f64::NAN`]).
6///
7/// # Additional Implementations on Foreign Types
8///
9/// ## Built-in Types
10///
11/// If the feature `"implement-IsNAN-for-built_ins"`
12/// is defined (as it is by `"default"`), then this is also implemented
13/// for the following types:
14/// - [`f32`];
15/// - [`f64`];
16pub trait IsNAN {
17    fn is_nan(&self) -> bool;
18}
19
20
21#[cfg(all(not(test), not(feature = "nostd")))]
22impl<T : IsNAN + ?Sized> IsNAN for Box<T> {
23    fn is_nan(&self) -> bool {
24        (**self).is_nan()
25    }
26}
27
28#[cfg(all(not(test), not(feature = "nostd")))]
29impl<T : IsNAN + ?Sized> IsNAN for std::rc::Rc<T> {
30    fn is_nan(&self) -> bool {
31        (**self).is_nan()
32    }
33}
34
35
36#[cfg(feature = "implement-IsNAN-for-built_ins")]
37mod impl_for_built_ins {
38    #![allow(non_snake_case)]
39
40    macro_rules! implement_IsNAN_ {
41        ($type:tt) => {
42            impl super::IsNAN for $type {
43                #[inline]
44                fn is_nan(&self) -> bool {
45                    $type::is_nan(*self)
46                }
47            }
48        };
49    }
50
51    implement_IsNAN_!(f32);
52    implement_IsNAN_!(f64);
53}
54
55
56// ///////////////////////////// end of file //////////////////////////// //
57