SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
num_formatting.cpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include "
tests.hpp
"
19
20
#include <
core/wireUtils.hpp
>
21
#include <
utils/num_formatting.hpp
>
22
23
#include <string>
24
#include <tuple>
25
#include <vector>
26
27
using namespace
SILICON::core
;
28
29
TEST
(NumFormattingTest, FormatsKnownValues)
30
{
31
const
auto
value =
busValueFromBits
(
"1010"
);
32
33
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Raw
),
"1010"
);
34
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Unsigned
),
"10"
);
35
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Signed
),
"-6"
);
36
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Hex
),
"0xA"
);
37
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Oct
),
"0o12"
);
38
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Bin
),
"0b1010"
);
39
EXPECT_EQ(
formatValue
(
busValueFromInteger
(10, 8),
BusValueFormat::Hex
, 2),
"0x0A"
);
40
}
41
42
TEST
(NumFormattingTest, MaxValueHasNoMachineIntegerWidthLimit)
43
{
44
EXPECT_EQ(
maxValueForBusWidth
(4),
busValueFromBits
(
"1111"
));
45
EXPECT_EQ(
maxValueForBusWidth
(128),
BusValue
(128,
State::HIGH
));
46
}
47
48
TEST
(NumFormattingTest, ParsesSupportedNumericFormats)
49
{
50
for
(
const
auto
& [text, expectedFormat, expectedWidth] :
51
std::vector<std::tuple<std::string, BusValueFormat, std::size_t>>{
52
{
"42"
,
BusValueFormat::Unsigned
, 6},
53
{
" 0x2a "
,
BusValueFormat::Hex
, 8},
54
{
"0o52"
,
BusValueFormat::Oct
, 6},
55
{
"0b101010"
,
BusValueFormat::Bin
, 6}}) {
56
const
auto
[value, format] =
valueFromStr
(text);
57
EXPECT_EQ(format, expectedFormat);
58
EXPECT_EQ(value.size(), expectedWidth);
59
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Unsigned
),
"42"
);
60
}
61
62
const
auto
[hexWithE, format] =
valueFromStr
(
"0xFE"
);
63
EXPECT_EQ(format,
BusValueFormat::Hex
);
64
EXPECT_EQ(hexWithE,
busValueFromBits
(
"11111110"
));
65
}
66
67
TEST
(NumFormattingTest, ParsesFourStateRawValuesAsMsbFirst)
68
{
69
const
auto
[binaryValue, binaryFormat] =
valueFromStr
(
"1010"
);
70
EXPECT_EQ(binaryFormat,
BusValueFormat::Raw
);
71
EXPECT_EQ(binaryValue,
busValueFromBits
(
"1010"
));
72
73
const
auto
[value, format] =
valueFromStr
(
"10xE"
);
74
EXPECT_EQ(format,
BusValueFormat::Raw
);
75
EXPECT_EQ(value,
BusValue
({
State::ERROR
,
State::UNKNOWN
,
State::LOW
,
State::HIGH
}));
76
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Raw
),
"10XE"
);
77
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Hex
),
"10XE"
);
78
}
79
80
TEST
(NumFormattingTest, RejectsInvalidInput)
81
{
82
EXPECT_EQ(
valueFromStr
(
""
).format,
BusValueFormat::Unknown
);
83
EXPECT_EQ(
valueFromStr
(
"0b102"
).format,
BusValueFormat::Unknown
);
84
EXPECT_EQ(
valueFromStr
(
"10Z1"
).format,
BusValueFormat::Unknown
);
85
EXPECT_EQ(
valueFromStr
(
"-0x2a"
).format,
BusValueFormat::Unknown
);
86
EXPECT_THROW((
void
)
busValueFromBits
(
"10Z1"
), std::invalid_argument);
87
}
88
89
TEST
(NumFormattingTest, SignedUsesTwosComplementWidth)
90
{
91
EXPECT_EQ(
formatValue
(
busValueFromBits
(
"1111"
),
BusValueFormat::Signed
),
"-1"
);
92
EXPECT_EQ(
formatValue
(
busValueFromBits
(
"1000"
),
BusValueFormat::Signed
),
"-8"
);
93
EXPECT_EQ(
formatValue
(
busValueFromBits
(
"0111"
),
BusValueFormat::Signed
),
"7"
);
94
95
const
auto
[negative, format] =
valueFromStr
(
"-42"
);
96
EXPECT_EQ(format,
BusValueFormat::Signed
);
97
EXPECT_EQ(
formatValue
(negative,
BusValueFormat::Signed
),
"-42"
);
98
}
99
100
TEST
(NumFormattingTest, ResizesParsedSignedValuesWithTwosComplementSemantics)
101
{
102
const
auto
expectResize = [](
const
std::string_view text,
const
std::size_t width,
103
const
std::string_view expected) {
104
const
auto
resized =
resizeParsedValue
(
valueFromStr
(text), width);
105
ASSERT_TRUE(resized) << text <<
" at "
<< width <<
" bits"
;
106
EXPECT_EQ(
formatValue
(*resized,
BusValueFormat::Raw
), expected);
107
};
108
109
expectResize(
"-1"
, 1,
"1"
);
110
expectResize(
"-1"
, 4,
"1111"
);
111
expectResize(
"-1"
, 8,
"11111111"
);
112
expectResize(
"-8"
, 4,
"1000"
);
113
expectResize(
"-8"
, 8,
"11111000"
);
114
expectResize(
"127"
, 8,
"01111111"
);
115
116
EXPECT_FALSE(
resizeParsedValue
(
valueFromStr
(
"-9"
), 4));
117
EXPECT_FALSE(
resizeParsedValue
(
valueFromStr
(
"+128"
), 8));
118
}
119
120
TEST
(NumFormattingTest, ResizesUnsignedAndRawValuesWithZeroExtension)
121
{
122
EXPECT_EQ(
resizeParsedValue
(
valueFromStr
(
"255"
), 8),
busValueFromBits
(
"11111111"
));
123
EXPECT_FALSE(
resizeParsedValue
(
valueFromStr
(
"256"
), 8));
124
EXPECT_EQ(
resizeParsedValue
(
valueFromStr
(
"0b101"
), 8),
busValueFromBits
(
"00000101"
));
125
EXPECT_EQ(
resizeParsedValue
(
valueFromStr
(
"X"
), 8),
BusValue
(8,
State::UNKNOWN
));
126
127
const
auto
wide =
valueFromStr
(
"36893488147419103231"
);
128
EXPECT_TRUE(
resizeParsedValue
(wide, 65));
129
EXPECT_FALSE(
resizeParsedValue
(wide, 64));
130
}
131
132
TEST
(NumFormattingTest, NumericFitChecksAreSeparateFromBitVectorNormalization)
133
{
134
EXPECT_TRUE(
SILICON::wireUtils::fitsUnsigned
(
busValueFromBits
(
"000001"
), 4));
135
EXPECT_FALSE(
SILICON::wireUtils::fitsUnsigned
(
busValueFromBits
(
"100001"
), 4));
136
EXPECT_TRUE(
SILICON::wireUtils::fitsSigned
(
busValueFromBits
(
"11111"
), 1));
137
EXPECT_TRUE(
SILICON::wireUtils::fitsSigned
(
busValueFromBits
(
"11000"
), 4));
138
EXPECT_FALSE(
SILICON::wireUtils::fitsSigned
(
busValueFromBits
(
"10111"
), 4));
139
140
EXPECT_EQ(
SILICON::wireUtils::normalizeBusValue
(
busValueFromBits
(
"100001"
), 4),
141
busValueFromBits
(
"0001"
));
142
EXPECT_EQ(
SILICON::wireUtils::normalizeBusValue
(
busValueFromBits
(
"1"
), 4,
State::HIGH
),
143
busValueFromBits
(
"1111"
));
144
}
145
146
TEST
(NumFormattingTest, SupportsValuesWiderThanMachineIntegers)
147
{
148
EXPECT_EQ(
formatValue
(
BusValue
(65,
State::HIGH
),
BusValueFormat::Unsigned
),
149
"36893488147419103231"
);
150
EXPECT_EQ(
151
formatValue
(
busValueFromBits
(
"1"
+ std::string(64,
'0'
)),
BusValueFormat::Signed
),
152
"-18446744073709551616"
);
153
154
const
auto
[wide, format] =
valueFromStr
(
"36893488147419103231"
);
155
EXPECT_EQ(format,
BusValueFormat::Unsigned
);
156
EXPECT_EQ(wide,
BusValue
(65,
State::HIGH
));
157
}
158
159
TEST
(NumFormattingTest, RoundTripsArbitraryPrecisionValuesAcrossNumericBases)
160
{
161
const
std::string decimal =
162
"115792089237316195423570985008687907853269984665640564039457584007913129639935"
;
163
const
auto
value =
BusValue
(256,
State::HIGH
);
164
165
EXPECT_EQ(
formatValue
(value,
BusValueFormat::Unsigned
), decimal);
166
EXPECT_EQ(
valueFromStr
(decimal).value, value);
167
EXPECT_EQ(
valueFromStr
(
"000"
+ decimal).value, value);
168
169
const
auto
hex =
valueFromStr
(
"0x"
+ std::string(64,
'F'
));
170
EXPECT_EQ(hex.format,
BusValueFormat::Hex
);
171
EXPECT_EQ(hex.value, value);
172
EXPECT_EQ(
formatValue
(hex.value,
BusValueFormat::Hex
),
"0x"
+ std::string(64,
'F'
));
173
174
const
auto
octal =
valueFromStr
(
"0o"
+ std::string(86,
'7'
));
175
EXPECT_EQ(octal.format,
BusValueFormat::Oct
);
176
EXPECT_EQ(octal.value.size(), 258);
177
EXPECT_EQ(
formatValue
(octal.value,
BusValueFormat::Oct
),
"0o"
+ std::string(86,
'7'
));
178
}
179
180
TEST
(NumFormattingTest, PreservesExplicitBaseWidthsWhenParsingLeadingZeroes)
181
{
182
EXPECT_EQ(
valueFromStr
(
"0b0001"
).value,
busValueFromBits
(
"0001"
));
183
EXPECT_EQ(
valueFromStr
(
"0x01"
).value,
busValueFromBits
(
"00000001"
));
184
EXPECT_EQ(
valueFromStr
(
"0o01"
).value,
busValueFromBits
(
"000001"
));
185
}
186
187
TEST
(NumFormattingTest, FormatsWidthLimitedIntegers)
188
{
189
EXPECT_EQ(
formatInteger
(0xf3,
BusValueFormat::Signed
, 8),
"-13"
);
190
EXPECT_EQ(
formatInteger
(0xf3,
BusValueFormat::Unsigned
, 8),
"243"
);
191
EXPECT_EQ(
formatInteger
(0xf3,
BusValueFormat::Bin
, 8),
"11110011"
);
192
EXPECT_EQ(
formatInteger
(0xf3,
BusValueFormat::Oct
, 8),
"363"
);
193
EXPECT_EQ(
formatInteger
(0x0ff3,
BusValueFormat::Signed
, 16),
"4083"
);
194
EXPECT_EQ(
formatInteger
(0xffffffffffffffffULL,
BusValueFormat::Signed
, 64),
"-1"
);
195
}
196
197
TEST
(NumFormattingTest, ParsesWidthLimitedIntegers)
198
{
199
EXPECT_EQ(
parseInteger
(
"-128"
,
BusValueFormat::Signed
, 8), 0x80);
200
EXPECT_EQ(
parseInteger
(
"127"
,
BusValueFormat::Signed
, 8), 0x7f);
201
EXPECT_EQ(
parseInteger
(
"255"
,
BusValueFormat::Unsigned
, 8), 0xff);
202
EXPECT_EQ(
parseInteger
(
"0b11110011"
,
BusValueFormat::Bin
, 8), 0xf3);
203
EXPECT_EQ(
parseInteger
(
"0o363"
,
BusValueFormat::Oct
, 8), 0xf3);
204
EXPECT_EQ(
parseInteger
(
"0xF3"
,
BusValueFormat::Hex
, 8), 0xf3);
205
EXPECT_EQ(
parseInteger
(
"18446744073709551615"
,
BusValueFormat::Unsigned
, 64),
206
BigInt
(
"18446744073709551615"
));
207
EXPECT_FALSE(
parseInteger
(
"-129"
,
BusValueFormat::Signed
, 8));
208
EXPECT_FALSE(
parseInteger
(
"128"
,
BusValueFormat::Signed
, 8));
209
EXPECT_FALSE(
parseInteger
(
"256"
,
BusValueFormat::Unsigned
, 8));
210
EXPECT_FALSE(
parseInteger
(
"0b102"
,
BusValueFormat::Bin
, 8));
211
EXPECT_FALSE(
parseInteger
(
"1"
,
BusValueFormat::Raw
, 8));
212
EXPECT_FALSE(
parseInteger
(
"1"
,
BusValueFormat::Unknown
, 8));
213
}
214
215
TEST
(NumFormattingTest, FormatsArbitraryPrecisionIntegers)
216
{
217
const
BigInt
value(
"340282366920938463463374607431768211455"
);
218
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Unsigned
, 128), value.str());
219
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Signed
, 128),
"-1"
);
220
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Hex
, 128), std::string(32,
'F'
));
221
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Oct
, 128),
"3"
+ std::string(42,
'7'
));
222
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Bin
, 128), std::string(128,
'1'
));
223
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Unsigned
, 65),
"36893488147419103231"
);
224
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Unsigned
, 8),
"255"
);
225
EXPECT_EQ(
formatInteger
(value,
BusValueFormat::Bin
, 129),
"0"
+ std::string(128,
'1'
));
226
EXPECT_EQ(
formatInteger
(-value,
BusValueFormat::Unsigned
, 128),
"1"
);
227
EXPECT_EQ(
formatInteger
(-1,
BusValueFormat::Hex
, 128), std::string(32,
'F'
));
228
229
const
BigInt
minimum = -(
BigInt
{1} << 127);
230
EXPECT_EQ(
formatInteger
(minimum,
BusValueFormat::Signed
, 128), minimum.str());
231
}
232
233
TEST
(NumFormattingTest, ParsesArbitraryPrecisionIntegersAcrossNumericBases)
234
{
235
const
BigInt
maximum(
"340282366920938463463374607431768211455"
);
236
EXPECT_EQ(
parseInteger
(maximum.str(),
BusValueFormat::Unsigned
, 128), maximum);
237
EXPECT_EQ(
parseInteger
(
" +"
+ maximum.str() +
" "
,
BusValueFormat::Unsigned
, 128),
238
maximum);
239
EXPECT_EQ(
parseInteger
(
"0x"
+ std::string(32,
'F'
),
BusValueFormat::Hex
, 128), maximum);
240
EXPECT_EQ(
parseInteger
(
"0o3"
+ std::string(42,
'7'
),
BusValueFormat::Oct
, 128),
241
maximum);
242
EXPECT_EQ(
parseInteger
(
"0b"
+ std::string(128,
'1'
),
BusValueFormat::Bin
, 128),
243
maximum);
244
245
const
BigInt
overflow = maximum + 1;
246
EXPECT_FALSE(
parseInteger
(overflow.str(),
BusValueFormat::Unsigned
, 128));
247
EXPECT_FALSE(
parseInteger
(
"0x1"
+ std::string(32,
'0'
),
BusValueFormat::Hex
, 128));
248
EXPECT_FALSE(
parseInteger
(
"0o4"
+ std::string(42,
'0'
),
BusValueFormat::Oct
, 128));
249
EXPECT_FALSE(
parseInteger
(
"0b1"
+ std::string(128,
'0'
),
BusValueFormat::Bin
, 128));
250
}
251
252
TEST
(NumFormattingTest, ParsesArbitraryPrecisionSignedBounds)
253
{
254
const
BigInt
signBit =
BigInt
{1} << 127;
255
const
BigInt
minimum = -signBit;
256
const
BigInt
maximum = signBit - 1;
257
EXPECT_EQ(
parseInteger
(minimum.str(),
BusValueFormat::Signed
, 128), signBit);
258
EXPECT_EQ(
parseInteger
(maximum.str(),
BusValueFormat::Signed
, 128), maximum);
259
EXPECT_EQ(
parseInteger
(
"-1"
,
BusValueFormat::Signed
, 128), (
BigInt
{1} << 128) - 1);
260
EXPECT_EQ(
parseInteger
(
"-0"
,
BusValueFormat::Signed
, 128), 0);
261
262
const
BigInt
underflow = minimum - 1;
263
EXPECT_FALSE(
parseInteger
(underflow.str(),
BusValueFormat::Signed
, 128));
264
EXPECT_FALSE(
parseInteger
(signBit.str(),
BusValueFormat::Signed
, 128));
265
}
266
267
TEST
(NumFormattingTest, ConvertsArbitraryPrecisionIntegersToFixedWidthBusValues)
268
{
269
const
BigInt
value = (
BigInt
{1} << 128) + 5;
270
EXPECT_EQ(
busValueFromInteger
(value, 129),
271
busValueFromBits
(
"1"
+ std::string(125,
'0'
) +
"101"
));
272
EXPECT_EQ(
busValueFromInteger
(value, 8),
busValueFromBits
(
"00000101"
));
273
EXPECT_EQ(
busValueFromInteger
(0, 128),
BusValue
(128,
State::LOW
));
274
EXPECT_TRUE(
busValueFromInteger
(value, 0).empty());
275
}
276
277
TEST
(NumFormattingTest, ConvertsBusValuesToUnsignedArbitraryPrecisionIntegers)
278
{
279
const
BigInt
value = (
BigInt
{1} << 128) + 5;
280
EXPECT_EQ(
integerFromBusValue
(
busValueFromInteger
(value, 256)), value);
281
EXPECT_EQ(
integerFromBusValue
(
busValueFromBits
(
"1111"
)), 15);
282
EXPECT_EQ(
integerFromBusValue
(
BusValue
(128,
State::LOW
)), 0);
283
EXPECT_EQ(
integerFromBusValue
({}), 0);
284
}
285
286
TEST
(NumFormattingTest, RejectsNonbinaryBusValuesWhenConvertingToIntegers)
287
{
288
EXPECT_THROW((
void
)
integerFromBusValue
(
busValueFromBits
(
"10X1"
)),
289
std::invalid_argument);
290
EXPECT_THROW((
void
)
integerFromBusValue
(
busValueFromBits
(
"10E1"
)),
291
std::invalid_argument);
292
}
293
294
TEST
(NumFormattingTest, ConvertsNegativeIntegersToTwosComplementBusValues)
295
{
296
EXPECT_EQ(
busValueFromInteger
(-1, 1),
busValueFromBits
(
"1"
));
297
EXPECT_EQ(
busValueFromInteger
(-1, 128),
BusValue
(128,
State::HIGH
));
298
EXPECT_EQ(
busValueFromInteger
(-8, 4),
busValueFromBits
(
"1000"
));
299
EXPECT_EQ(
busValueFromInteger
(-8, 8),
busValueFromBits
(
"11111000"
));
300
EXPECT_EQ(
busValueFromInteger
(-129, 8),
busValueFromBits
(
"01111111"
));
301
EXPECT_TRUE(
busValueFromInteger
(-1, 0).empty());
302
303
const
BigInt
minimum = -(
BigInt
{1} << 127);
304
EXPECT_EQ(
busValueFromInteger
(minimum, 128),
305
busValueFromBits
(
"1"
+ std::string(127,
'0'
)));
306
EXPECT_EQ(
busValueFromInteger
(minimum + 5, 128),
307
busValueFromBits
(
"1"
+ std::string(124,
'0'
) +
"101"
));
308
EXPECT_EQ(
busValueFromInteger
(minimum - 1, 128),
309
busValueFromBits
(
"0"
+ std::string(127,
'1'
)));
310
EXPECT_EQ(
busValueFromInteger
(minimum - 5, 8),
busValueFromBits
(
"11111011"
));
311
}
312
313
TEST
(NumFormattingTest, EnforcesIntegerWidthsAndFormats)
314
{
315
EXPECT_THROW((
void
)
formatInteger
(1,
BusValueFormat::Unsigned
, 0),
316
std::invalid_argument);
317
EXPECT_THROW((
void
)
formatInteger
(1,
BusValueFormat::Raw
, 128), std::invalid_argument);
318
EXPECT_THROW((
void
)
formatInteger
(1,
BusValueFormat::Unknown
, 128),
319
std::invalid_argument);
320
EXPECT_FALSE(
parseInteger
(
"1"
,
BusValueFormat::Unsigned
, 0));
321
EXPECT_FALSE(
parseInteger
(
""
,
BusValueFormat::Unsigned
, 128));
322
EXPECT_FALSE(
parseInteger
(
"-1"
,
BusValueFormat::Unsigned
, 128));
323
EXPECT_FALSE(
parseInteger
(
"+"
,
BusValueFormat::Signed
, 128));
324
EXPECT_EQ(
parseInteger
(
"-1"
,
BusValueFormat::Signed
, 1), 1);
325
EXPECT_EQ(
parseInteger
(
"0"
,
BusValueFormat::Signed
, 1), 0);
326
EXPECT_FALSE(
parseInteger
(
"1"
,
BusValueFormat::Signed
, 1));
327
}
SILICON::core
Definition
activeKeyGuard.hpp:28
SILICON::core::valueFromStr
ParsedBusValue valueFromStr(const std::string_view value)
Parse user-facing decimal, hexadecimal, octal, binary, or four-state text.
Definition
num_formatting.cpp:355
SILICON::core::BigInt
boost::multiprecision::cpp_int BigInt
Definition
num_formatting.hpp:31
SILICON::core::parseInteger
std::optional< BigInt > parseInteger(std::string_view text, const BusValueFormat format, const std::size_t bitWidth)
Definition
num_formatting.cpp:198
SILICON::core::resizeParsedValue
std::optional< BusValue > resizeParsedValue(const ParsedBusValue &parsed, const std::size_t width)
Adapts a parsed textual value to an exact destination width.
Definition
num_formatting.cpp:394
SILICON::core::integerFromBusValue
BigInt integerFromBusValue(const BusValue &value, const Signedness signedness)
Decodes an LSB-first BusValue as an unsigned arbitrary-precision integer. Empty values yield zero....
Definition
num_formatting.cpp:272
SILICON::core::maxValueForBusWidth
BusValue maxValueForBusWidth(const std::size_t width)
Definition
num_formatting.cpp:252
SILICON::core::busValueFromBits
BusValue busValueFromBits(const std::string_view bits)
Strictly decodes an MSB-first raw string containing 0, 1, X, or E.
Definition
num_formatting.cpp:295
SILICON::core::BusValueFormat::Oct
@ Oct
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Raw
@ Raw
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Signed
@ Signed
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Bin
@ Bin
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Unknown
@ Unknown
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Hex
@ Hex
Definition
num_formatting.hpp:33
SILICON::core::BusValueFormat::Unsigned
@ Unsigned
Definition
num_formatting.hpp:33
SILICON::core::formatInteger
std::string formatInteger(const BigInt &value, const BusValueFormat format, const std::size_t bitWidth)
Definition
num_formatting.cpp:166
SILICON::core::busValueFromInteger
BusValue busValueFromInteger(const BigInt &value, const std::size_t width)
Builds an LSB-first BusValue from the low width bits of an integer. Negative values use two's complem...
Definition
num_formatting.cpp:257
SILICON::core::formatValue
std::string formatValue(const BusValue &value, const BusValueFormat format, const std::size_t fixedWidth)
Format an LSB-first BusValue for display.
Definition
num_formatting.cpp:311
SILICON::core::State::LOW
@ LOW
Definition
wire.hpp:38
SILICON::core::State::UNKNOWN
@ UNKNOWN
Definition
wire.hpp:40
SILICON::core::State::HIGH
@ HIGH
Definition
wire.hpp:39
SILICON::core::State::ERROR
@ ERROR
Definition
wire.hpp:41
SILICON::core::BusValue
std::vector< State > BusValue
Definition
wire.hpp:120
SILICON::wireUtils::normalizeBusValue
BusValue normalizeBusValue(const BusValue &value, const std::size_t width, const State extension)
Resize an LSB-first value to an exact bus width.
Definition
wire.cpp:121
SILICON::wireUtils::fitsUnsigned
bool fitsUnsigned(const BusValue &value, const std::size_t width)
Tests whether an LSB-first value is representable as an unsigned value.
Definition
wire.cpp:97
SILICON::wireUtils::fitsSigned
bool fitsSigned(const BusValue &value, const std::size_t width)
Tests whether an LSB-first two's-complement value fits a signed width.
Definition
wire.cpp:105
num_formatting.hpp
TEST
TEST(NumFormattingTest, FormatsKnownValues)
Definition
num_formatting.cpp:29
tests.hpp
wireUtils.hpp
tests
num_formatting.cpp
Generated by
1.17.0