logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/// Internal namespace.
pub( crate ) mod private
{
  use crate::*;

  ///
  /// Implement check is it nan and constructor with NAN value.
  ///

  pub trait NanLikeInterface
  {
    /// Construct NAN-like. If the type does not have NAN value in codomain of the type it should return default value.
    fn make_nan_like() -> Self;
    /// Is current value NAN? Always false if codomain of the type does not have NAN value.
    fn is_nan( &self ) -> bool;
  }

  //

  macro_rules! impl_nan_like_for_integer
  {
    (
      $( $Args : tt )*
    ) =>
    {
      impl NanLikeInterface for $( $Args )*
      {
        #[ inline ]
        fn make_nan_like() -> Self
        {
          0
        }
        #[ inline ]
        fn is_nan( &self ) -> bool
        {
          false
        }
      }
    };
  }

  //

  macro_rules! impl_nan_like_for_float
  {
    (
      $( $Args : tt )*
    ) =>
    {
      impl NanLikeInterface for $( $Args )*
      {
        #[ inline ]
        fn make_nan_like() -> Self
        {
          < $( $Args )* >::NAN
        }
        #[ inline ]
        fn is_nan( &self ) -> bool
        {
          *self == < $( $Args )* >::NAN
        }
      }
    };
  }

  for_each_int!( impl_nan_like_for_integer );
  for_each_float!( impl_nan_like_for_float );

}

crate::mod_interface!
{
  prelude use NanLikeInterface;
}