math_adapter/abs/
nan_like.rs

1//!
2//! Define several traits like NanLikeInterface.
3//!
4
5/// Internal namespace.
6pub( crate ) mod private
7{
8  use crate::*;
9
10  ///
11  /// Implement check is it nan and constructor with NAN value.
12  ///
13
14  pub trait NanLikeInterface
15  {
16    /// Construct NAN-like. If the type does not have NAN value in codomain of the type it should return default value.
17    fn make_nan_like() -> Self;
18    /// Is current value NAN? Always false if codomain of the type does not have NAN value.
19    fn is_nan( &self ) -> bool;
20  }
21
22  //
23
24  macro_rules! impl_nan_like_for_integer
25  {
26    (
27      $( $Args : tt )*
28    ) =>
29    {
30      impl NanLikeInterface for $( $Args )*
31      {
32        #[ inline ]
33        fn make_nan_like() -> Self
34        {
35          0
36        }
37        #[ inline ]
38        fn is_nan( &self ) -> bool
39        {
40          false
41        }
42      }
43    };
44  }
45
46  //
47
48  macro_rules! impl_nan_like_for_float
49  {
50    (
51      $( $Args : tt )*
52    ) =>
53    {
54      impl NanLikeInterface for $( $Args )*
55      {
56        #[ inline ]
57        fn make_nan_like() -> Self
58        {
59          < $( $Args )* >::NAN
60        }
61        #[ inline ]
62        fn is_nan( &self ) -> bool
63        {
64          *self == < $( $Args )* >::NAN
65        }
66      }
67    };
68  }
69
70  for_each_int!( impl_nan_like_for_integer );
71  for_each_float!( impl_nan_like_for_float );
72
73}
74
75crate::mod_interface!
76{
77  prelude use NanLikeInterface;
78}