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
//! (private) fmt: private module containing implementation of traits
//! pertaining to I/O formatting.

use crate::traits::Digit;
use crate::BigInt;

impl<T: Digit> std::fmt::LowerExp for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let val = f64::from(self);
        std::fmt::LowerExp::fmt(&val, f)
    }
}
impl<T: Digit> std::fmt::UpperExp for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let val = f64::from(self);
        std::fmt::UpperExp::fmt(&val, f)
    }
}

impl<T: Digit> std::fmt::LowerHex for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut ret = match self.sign {
            true => "".to_string(),
            false => "-".to_string(),
        };
        ret.push_str(&format!("{:x}", self.uint));
        write!(f, "{}", ret)
    }
}
impl<T: Digit> std::fmt::UpperHex for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut ret = match self.sign {
            true => "".to_string(),
            false => "-".to_string(),
        };
        ret.push_str(&format!("{:X}", self.uint));
        write!(f, "{}", ret)
    }
}

impl<T: Digit> std::fmt::Display for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", String::from(self))
    }
}

impl<T: Digit> std::fmt::Binary for BigInt<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut ret = match self.sign {
            true => "".to_string(),
            false => "-".to_string(),
        };
        ret.push_str(&format!("{:b}", self.uint));
        write!(f, "{}", ret)
    }
}