Fix exponentional notation in number literals

This commit is contained in:
Alex Beregszaszi 2017-02-14 14:24:25 +00:00
parent f1dd79c743
commit 924a8fff6b
2 changed files with 28 additions and 4 deletions

View File

@ -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:

View File

@ -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),