|
2 | 2 |
|
3 | 3 | // Test if a binary number is zero. |
4 | 4 | bool binEQZero(const bin x) { |
5 | | - for (bin_int_t i = 0; i < BIN_BITS; i++) { |
6 | | - if (x.bits[i]) |
7 | | - return false; |
8 | | - } |
9 | | - return true; |
| 5 | + for (bin_int_t i = 0; i < BIN_BITS; i++) { |
| 6 | + if (x.bits[i]) |
| 7 | + return false; |
| 8 | + } |
| 9 | + return true; |
10 | 10 | } |
11 | 11 |
|
12 | 12 | // Test if a binary number is one. |
13 | 13 | bool binEQOne(const bin x) { |
14 | | - // Check if the least significant bit is 1 and all others are 0 |
15 | | - if (!x.bits[0]) |
16 | | - return false; |
17 | | - for (bin_int_t i = 1; i < BIN_BITS; i++) { |
18 | | - if (x.bits[i]) |
19 | | - return false; |
20 | | - } |
21 | | - return true; |
| 14 | + // Check if the least significant bit is 1 and all others are 0 |
| 15 | + if (!x.bits[0]) |
| 16 | + return false; |
| 17 | + for (bin_int_t i = 1; i < BIN_BITS; i++) { |
| 18 | + if (x.bits[i]) |
| 19 | + return false; |
| 20 | + } |
| 21 | + return true; |
22 | 22 | } |
23 | 23 |
|
24 | 24 | // Test if a binary number is the maximum value. |
25 | 25 | bool binEQMax(const bin x) { |
26 | | - for (bin_int_t i = 0; i < BIN_BITS; i++) { |
27 | | - if (!x.bits[i]) |
28 | | - return false; |
29 | | - } |
30 | | - return true; |
| 26 | + for (bin_int_t i = 0; i < BIN_BITS; i++) { |
| 27 | + if (!x.bits[i]) |
| 28 | + return false; |
| 29 | + } |
| 30 | + return true; |
31 | 31 | } |
32 | 32 |
|
33 | 33 | // Test if two binary numbers are equal. |
34 | 34 | bool binEQ(const bin x, const bin y) { |
35 | | - for (bin_int_t i = 0; i < BIN_BITS; i++) { |
36 | | - if (x.bits[i] != y.bits[i]) |
37 | | - return false; |
38 | | - } |
39 | | - return true; |
| 35 | + for (bin_int_t i = 0; i < BIN_BITS; i++) { |
| 36 | + if (x.bits[i] != y.bits[i]) |
| 37 | + return false; |
| 38 | + } |
| 39 | + return true; |
40 | 40 | } |
41 | 41 |
|
42 | 42 | // Test if a binary number is greater than another. |
43 | 43 | bool binGT(const bin x, const bin y) { |
44 | | - for (int i = BIN_BITS-1; i >= 0; --i) { |
45 | | - if (x.bits[i] != y.bits[i]) |
46 | | - return x.bits[i] && !y.bits[i]; |
47 | | - } |
48 | | - return false; |
| 44 | + for (int i = BIN_BITS - 1; i >= 0; --i) { |
| 45 | + if (x.bits[i] != y.bits[i]) |
| 46 | + return x.bits[i] && !y.bits[i]; |
| 47 | + } |
| 48 | + return false; |
49 | 49 | } |
50 | 50 |
|
51 | | -// Test if a binary number is less than another. |
52 | | -bool binLT(const bin x, const bin y) { |
53 | | - return !binEQ(x, y) && !binGT(x, y); |
54 | | -} |
| 51 | +// Test if binary number is less than another. |
| 52 | +bool binLT(const bin x, const bin y) { return !binEQ(x, y) && !binGT(x, y); } |
55 | 53 |
|
56 | 54 | // Test if a binary number is greater than or equal to another. |
57 | | -bool binGTEQ(const bin x, const bin y) { |
58 | | - return !binLT(x, y); |
59 | | -} |
| 55 | +bool binGTEQ(const bin x, const bin y) { return !binLT(x, y); } |
60 | 56 |
|
61 | 57 | // Test if a binary number is less than or equal to another. |
62 | | -bool binLTEQ(const bin x, const bin y) { |
63 | | - return !binGT(x, y); |
64 | | -} |
| 58 | +bool binLTEQ(const bin x, const bin y) { return !binGT(x, y); } |
0 commit comments