mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix exponentional notation in number literals
This commit is contained in:
parent
f1dd79c743
commit
924a8fff6b
@ -5,6 +5,7 @@ Features:
|
||||
* Introduce ``.transfer(value)`` for sending Ether.
|
||||
* Code generator: Support ``revert()`` to abort with rolling back, but not consuming all gas.
|
||||
* Inline assembly: Support ``revert`` (EIP140) as an opcode.
|
||||
* Parser: Support scientific notation in numbers (e.g. ``2e8`` and ``200e-2``).
|
||||
* Type system: Support explicit conversion of external function to address.
|
||||
|
||||
Bugfixes:
|
||||
|
@ -576,11 +576,31 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
|
||||
rational x;
|
||||
try
|
||||
{
|
||||
rational numerator;
|
||||
rational denominator(1);
|
||||
|
||||
auto expPoint = find(_literal.value().begin(), _literal.value().end(), 'e');
|
||||
if (expPoint == _literal.value().end())
|
||||
expPoint = find(_literal.value().begin(), _literal.value().end(), 'E');
|
||||
auto radixPoint = find(_literal.value().begin(), _literal.value().end(), '.');
|
||||
if (radixPoint != _literal.value().end())
|
||||
|
||||
if (expPoint != _literal.value().end())
|
||||
{
|
||||
if (
|
||||
!all_of(_literal.value().begin(), expPoint, ::isdigit) ||
|
||||
!all_of(expPoint + 1, _literal.value().end(), ::isdigit)
|
||||
)
|
||||
return make_tuple(false, rational(0));
|
||||
|
||||
bigint exp = bigint(string(expPoint + 1, _literal.value().end()));
|
||||
|
||||
if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min())
|
||||
return make_tuple(false, rational(0));
|
||||
|
||||
x = bigint(string(_literal.value().begin(), expPoint));
|
||||
x *= boost::multiprecision::pow(
|
||||
bigint(10),
|
||||
exp.convert_to<int32_t>()
|
||||
);
|
||||
}
|
||||
else if (radixPoint != _literal.value().end())
|
||||
{
|
||||
if (
|
||||
!all_of(radixPoint + 1, _literal.value().end(), ::isdigit) ||
|
||||
@ -594,6 +614,9 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
|
||||
[](char const& a) { return a == '0'; }
|
||||
);
|
||||
|
||||
rational numerator;
|
||||
rational denominator(1);
|
||||
|
||||
denominator = bigint(string(fractionalBegin, _literal.value().end()));
|
||||
denominator /= boost::multiprecision::pow(
|
||||
bigint(10),
|
||||
|
Loading…
Reference in New Issue
Block a user