• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kaidokert / fixed-bigint-rs / KuaLV86X2KcNHP6AW4bgSzBZAVGVQHhMJ

07 Jul 2025 07:48AM UTC coverage: 84.267% (+0.4%) from 83.887%
KuaLV86X2KcNHP6AW4bgSzBZAVGVQHhMJ

push

github

web-flow
Implement Display, FromStr and Hash (#44)

* Implement Display, FromStr and Hash

* Renovate actions

* Fix CI

22 of 28 new or added lines in 3 files covered. (78.57%)

707 of 839 relevant lines covered (84.27%)

13.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.18
/src/fixeduint/prim_int_impl.rs
1
use super::{FixedUInt, MachineWord};
2

3
use num_traits::One;
4

5
impl<T: MachineWord, const N: usize> num_traits::PrimInt for FixedUInt<T, N> {
6
    fn count_ones(self) -> u32 {
6✔
7
        self.array.iter().map(|&val| val.count_ones()).sum()
18✔
8
    }
9
    fn count_zeros(self) -> u32 {
6✔
10
        self.array.iter().map(|&val| val.count_zeros()).sum()
18✔
11
    }
12
    fn leading_zeros(self) -> u32 {
11✔
13
        let mut ret = 0u32;
11✔
14
        for index in (0..N).rev() {
22✔
15
            let v = self.array[index];
22✔
16
            ret += v.leading_zeros();
22✔
17
            if !v.is_zero() {
11✔
18
                break;
×
19
            }
20
        }
21
        ret
11✔
22
    }
23
    fn trailing_zeros(self) -> u32 {
6✔
24
        let mut ret = 0u32;
6✔
25
        for index in 0..N {
12✔
26
            let v = self.array[index];
12✔
27
            ret += v.trailing_zeros();
12✔
28
            if !v.is_zero() {
6✔
29
                break;
×
30
            }
31
        }
32
        ret
6✔
33
    }
34
    fn rotate_left(self, bits: u32) -> Self {
6✔
35
        let a = self << bits;
6✔
36
        let b = self >> (Self::BIT_SIZE - bits as usize);
6✔
37
        a | b
6✔
38
    }
39
    fn rotate_right(self, bits: u32) -> Self {
6✔
40
        let a = self >> bits;
6✔
41
        let b = self << (Self::BIT_SIZE - bits as usize);
6✔
42
        a | b
6✔
43
    }
NEW
44
    fn signed_shl(self, bits: u32) -> Self {
×
NEW
45
        self.unsigned_shl(bits)
×
46
    }
NEW
47
    fn signed_shr(self, bits: u32) -> Self {
×
NEW
48
        self.unsigned_shr(bits)
×
49
    }
50
    fn unsigned_shl(self, bits: u32) -> Self {
3✔
51
        core::ops::Shl::<u32>::shl(self, bits)
3✔
52
    }
53
    fn unsigned_shr(self, bits: u32) -> Self {
3✔
54
        core::ops::Shr::<u32>::shr(self, bits)
3✔
55
    }
56
    fn swap_bytes(self) -> Self {
6✔
57
        let mut ret = Self::new();
6✔
58
        for index in 0..N {
12✔
59
            ret.array[index] = self.array[N - 1 - index].swap_bytes();
12✔
60
        }
61

62
        ret
6✔
63
    }
64
    fn from_be(source: Self) -> Self {
6✔
65
        let mut ret = Self::new();
6✔
66
        for index in 0..N {
12✔
67
            ret.array[index] = source.array[N - 1 - index].swap_bytes();
12✔
68
        }
69

70
        ret
6✔
71
    }
72
    fn from_le(source: Self) -> Self {
6✔
73
        let mut ret = Self::new();
6✔
74
        for index in 0..N {
12✔
75
            ret.array[index] = source.array[index];
12✔
76
        }
77

78
        ret
6✔
79
    }
80
    fn to_be(self) -> Self {
6✔
81
        let mut ret = Self::new();
6✔
82
        for index in 0..N {
12✔
83
            ret.array[index] = self.array[N - 1 - index].swap_bytes();
12✔
84
        }
85

86
        ret
6✔
87
    }
88
    fn to_le(self) -> Self {
6✔
89
        let mut ret = Self::new();
6✔
90
        for index in 0..N {
12✔
91
            ret.array[index] = self.array[index];
12✔
92
        }
93

94
        ret
6✔
95
    }
96
    fn pow(self, n: u32) -> Self {
6✔
97
        if n == 0 {
12✔
98
            Self::one()
6✔
99
        } else {
100
            let mut ret = self;
6✔
101
            for _ in 1..n {
12✔
102
                ret *= self;
6✔
103
            }
104
            ret
6✔
105
        }
106
    }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc