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
use crate::{
    Negative, NegativeFinite, NonNaN, NonNaNFinite, NonZeroNonNaN, NonZeroNonNaNFinite, Positive,
    PositiveFinite, StrictlyNegative, StrictlyNegativeFinite, StrictlyPositive,
    StrictlyPositiveFinite,
};

macro_rules! impl_display {
    ($test:ident, $type:ident) => {
        impl core::fmt::Display for $type<f32> {
            #[inline]
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                write!(f, "{}", self.0)
            }
        }

        impl core::fmt::Display for $type<f64> {
            #[inline]
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                write!(f, "{}", self.0)
            }
        }

        #[test]
        fn $test() {
            let values_f32 = crate::tf32::TEST_VALUES;

            for &value in &values_f32 {
                if let Ok(t) = $type::<f32>::new(value) {
                    let str1 = format!("{}", t);
                    let str2 = format!("{}", value);
                    assert_eq!(str1, str2);
                }
            }

            let values_f64 = crate::tf64::TEST_VALUES;

            for &value in &values_f64 {
                if let Ok(t) = $type::<f64>::new(value) {
                    let str1 = format!("{}", t);
                    let str2 = format!("{}", value);
                    assert_eq!(str1, str2);
                }
            }
        }
    };
}

impl_display!(non_nan, NonNaN);
impl_display!(non_zero_non_nan, NonZeroNonNaN);
impl_display!(non_nan_finite, NonNaNFinite);
impl_display!(non_zero_non_nan_finite, NonZeroNonNaNFinite);
impl_display!(positive, Positive);
impl_display!(negative, Negative);
impl_display!(positive_finite, PositiveFinite);
impl_display!(negative_finite, NegativeFinite);
impl_display!(strictly_positive, StrictlyPositive);
impl_display!(strictly_negative, StrictlyNegative);
impl_display!(strictly_positive_finite, StrictlyPositiveFinite);
impl_display!(strictly_negative_finite, StrictlyNegativeFinite);