diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-02-14 22:24:25 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-03-15 21:06:24 +0800 |
commit | 924a8fff6bc517519eb91ca73adf06505b3f5a87 (patch) | |
tree | de6db711e65ac15f1c56f05c39dec3fd31df729f /libsolidity/ast | |
parent | f1dd79c7433a6c78e879a0b597b0585921838f1e (diff) | |
download | dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar.gz dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar.bz2 dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar.lz dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar.xz dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.tar.zst dexon-solidity-924a8fff6bc517519eb91ca73adf06505b3f5a87.zip |
Fix exponentional notation in number literals
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/Types.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index d2793b6d..aecf830d 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -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), |