mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow more than 77 fractional digits.
This commit is contained in:
parent
96d50431bb
commit
3fe4b0b2c3
@ -62,7 +62,7 @@ The following elementary types exist:
|
|||||||
- ``bool``: equivalent to ``uint8`` restricted to the values 0 and 1. For computing the function selector, ``bool`` is used.
|
- ``bool``: equivalent to ``uint8`` restricted to the values 0 and 1. For computing the function selector, ``bool`` is used.
|
||||||
|
|
||||||
- ``fixed<M>x<N>``: signed fixed-point decimal number of ``M`` bits, ``8 <= M <= 256``,
|
- ``fixed<M>x<N>``: signed fixed-point decimal number of ``M`` bits, ``8 <= M <= 256``,
|
||||||
``M % 8 == 0``, and ``0 < N <= 80``, which denotes the value ``v`` as ``v / (10 ** N)``.
|
``M % 8 == 0``, and ``0 < N <= 77``, which denotes the value ``v`` as ``v / (10 ** N)``.
|
||||||
|
|
||||||
- ``ufixed<M>x<N>``: unsigned variant of ``fixed<M>x<N>``.
|
- ``ufixed<M>x<N>``: unsigned variant of ``fixed<M>x<N>``.
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(string const& _
|
|||||||
int n = parseSize(positionX + 1, _literal.end());
|
int n = parseSize(positionX + 1, _literal.end());
|
||||||
if (
|
if (
|
||||||
8 <= m && m <= 256 && m % 8 == 0 &&
|
8 <= m && m <= 256 && m % 8 == 0 &&
|
||||||
0 <= n && n <= 80
|
0 <= n && n <= 77
|
||||||
) {
|
) {
|
||||||
if (keyword == Token::UFixed)
|
if (keyword == Token::UFixed)
|
||||||
return make_tuple(Token::UFixedMxN, m, n);
|
return make_tuple(Token::UFixedMxN, m, n);
|
||||||
|
@ -670,7 +670,7 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits,
|
|||||||
m_totalBits(_totalBits), m_fractionalDigits(_fractionalDigits), m_modifier(_modifier)
|
m_totalBits(_totalBits), m_fractionalDigits(_fractionalDigits), m_modifier(_modifier)
|
||||||
{
|
{
|
||||||
solAssert(
|
solAssert(
|
||||||
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 80,
|
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 77,
|
||||||
"Invalid bit number(s) for fixed type: " +
|
"Invalid bit number(s) for fixed type: " +
|
||||||
util::toString(_totalBits) + "x" + util::toString(_fractionalDigits)
|
util::toString(_totalBits) + "x" + util::toString(_fractionalDigits)
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
contract test {
|
contract test {
|
||||||
function f() public {
|
function f() public {
|
||||||
ufixed256x18 a = ufixed256x18(1/3); a;
|
ufixed256x77 a = ufixed256x77(1/3); a;
|
||||||
ufixed248x18 b = ufixed248x18(1/3); b;
|
ufixed248x77 b = ufixed248x77(1/3); b;
|
||||||
ufixed8x1 c = ufixed8x1(1/3); c;
|
ufixed8x1 c = ufixed8x1(1/3); c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ contract C {
|
|||||||
bytes payable h;
|
bytes payable h;
|
||||||
bytes32 payable i;
|
bytes32 payable i;
|
||||||
fixed payable j;
|
fixed payable j;
|
||||||
fixed80x80 payable k;
|
fixed80x77 payable k;
|
||||||
ufixed payable l;
|
ufixed payable l;
|
||||||
ufixed80x80 payable m;
|
ufixed80x77 payable m;
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 9106: (22-29): State mutability can only be specified for address types.
|
// ParserError 9106: (22-29): State mutability can only be specified for address types.
|
||||||
|
@ -9,9 +9,9 @@ contract C {
|
|||||||
function h(bytes payable) public pure {}
|
function h(bytes payable) public pure {}
|
||||||
function i(bytes32 payable) public pure {}
|
function i(bytes32 payable) public pure {}
|
||||||
function j(fixed payable) public pure {}
|
function j(fixed payable) public pure {}
|
||||||
function k(fixed80x80 payable) public pure {}
|
function k(fixed80x77 payable) public pure {}
|
||||||
function l(ufixed payable) public pure {}
|
function l(ufixed payable) public pure {}
|
||||||
function m(ufixed80x80 payable) public pure {}
|
function m(ufixed80x77 payable) public pure {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 9106: (33-40): State mutability can only be specified for address types.
|
// ParserError 9106: (33-40): State mutability can only be specified for address types.
|
||||||
|
@ -10,9 +10,9 @@ contract C {
|
|||||||
bytes payable h;
|
bytes payable h;
|
||||||
bytes32 payable i;
|
bytes32 payable i;
|
||||||
fixed payable j;
|
fixed payable j;
|
||||||
fixed80x80 payable k;
|
fixed80x77 payable k;
|
||||||
ufixed payable l;
|
ufixed payable l;
|
||||||
ufixed80x80 payable m;
|
ufixed80x77 payable m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
@ -9,9 +9,9 @@ contract C {
|
|||||||
function h() public pure returns (bytes payable) {}
|
function h() public pure returns (bytes payable) {}
|
||||||
function i() public pure returns (bytes32 payable) {}
|
function i() public pure returns (bytes32 payable) {}
|
||||||
function j() public pure returns (fixed payable) {}
|
function j() public pure returns (fixed payable) {}
|
||||||
function k() public pure returns (fixed80x80 payable) {}
|
function k() public pure returns (fixed80x77 payable) {}
|
||||||
function l() public pure returns (ufixed payable) {}
|
function l() public pure returns (ufixed payable) {}
|
||||||
function m() public pure returns (ufixed80x80 payable) {}
|
function m() public pure returns (ufixed80x77 payable) {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 9106: (56-63): State mutability can only be specified for address types.
|
// ParserError 9106: (56-63): State mutability can only be specified for address types.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
contract C {
|
contract C {
|
||||||
fixed8x80 a = -1e-100;
|
fixed8x77 a = -1e-100;
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 7407: (29-36): Type rational_const -1 / 1000...(93 digits omitted)...0000 is not implicitly convertible to expected type fixed8x80. Conversion incurs precision loss. Use an explicit conversion instead.
|
// TypeError 7407: (29-36): Type rational_const -1 / 1000...(93 digits omitted)...0000 is not implicitly convertible to expected type fixed8x77. Conversion incurs precision loss. Use an explicit conversion instead.
|
||||||
|
Loading…
Reference in New Issue
Block a user