Skip to content

Commit 866617b

Browse files
aarltchriseth
authored andcommitted
[isoltest] Add support for fixed point types.
1 parent c0a9578 commit 866617b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

test/libsolidity/util/BytesUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size
232232
if (_fractionalDigits > 0)
233233
{
234234
size_t numDigits = decimal.length() - (negative ? 1 : 0);
235-
if (_fractionalDigits > numDigits)
236-
decimal.insert(negative ? 1 : 0, string(_fractionalDigits - numDigits, '0'));
235+
if (_fractionalDigits >= numDigits)
236+
decimal.insert(negative ? 1 : 0, string(_fractionalDigits + 1 - numDigits, '0'));
237237
decimal.insert(decimal.length() - _fractionalDigits, ".");
238238
}
239239
return decimal;

test/libsolidity/util/BytesUtilsTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ BOOST_AUTO_TEST_CASE(format_fixed)
3535
{
3636
BOOST_CHECK_EQUAL(
3737
BytesUtils::formatFixedPoint(toBigEndian(u256{0}), true, 2),
38-
".00"
38+
"0.00"
3939
);
4040
BOOST_CHECK_EQUAL(
4141
BytesUtils::formatFixedPoint(toBigEndian(u256{1}), true, 2),
42-
".01"
42+
"0.01"
4343
);
4444
BOOST_CHECK_EQUAL(
4545
BytesUtils::formatFixedPoint(toBigEndian(u256{123}), true, 2),
4646
"1.23"
4747
);
4848
BOOST_CHECK_EQUAL(
4949
BytesUtils::formatFixedPoint(toBigEndian(u256{-1}), true, 2),
50-
"-.01"
50+
"-0.01"
5151
);
5252
BOOST_CHECK_EQUAL(
5353
BytesUtils::formatFixedPoint(toBigEndian(u256{-12}), true, 2),
54-
"-.12"
54+
"-0.12"
5555
);
5656
BOOST_CHECK_EQUAL(
5757
BytesUtils::formatFixedPoint(toBigEndian(u256{-123}), true, 2),

0 commit comments

Comments
 (0)