Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib/parse/LibParseDecimalFloat.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {LibParseChar} from "rain-string-0.2.0/src/lib/parse/LibParseChar.sol";
import {
CMASK_NUMERIC_0_9,
CMASK_NEGATIVE_SIGN,
CMASK_PLUS_SIGN,
CMASK_E_NOTATION,
CMASK_ZERO,
CMASK_DECIMAL_POINT
Expand Down Expand Up @@ -142,6 +143,12 @@ library LibParseDecimalFloat {
cursor++;
uint256 eStart = cursor;
cursor = LibParseChar.skipMask(cursor, end, CMASK_NEGATIVE_SIGN);
// Skip an optional explicit positive sign (e.g. 1e+2). Advance
// eStart past it so the int parser only sees the digit string.
if (LibParseChar.isMask(cursor, end, CMASK_PLUS_SIGN) == 1) {
cursor++;
eStart = cursor;
}
{
uint256 digitsStart = cursor;
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
Expand Down
19 changes: 19 additions & 0 deletions test/src/lib/parse/LibParseDecimalFloat.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,25 @@ contract LibParseDecimalFloatTest is Test {
checkParseDecimalFloatFail("e.", ParseEmptyDecimalString.selector, 0);
}

/// Explicit positive exponent sign is accepted and equivalent to no sign.
function testParseLiteralDecimalFloatPositiveExponentSign() external pure {
checkParseDecimalFloat("1e+2", 1, 2, 4);
checkParseDecimalFloat("1.0e+2", 1, 2, 6);
checkParseDecimalFloat("1E+2", 1, 2, 4);
checkParseDecimalFloat("0e+0", 0, 0, 4);
checkParseDecimalFloat("0e+1", 0, 0, 4);
checkParseDecimalFloat("1e+0", 1, 0, 4);
checkParseDecimalFloat("1e+260", 1, 260, 6);
checkParseDecimalFloat("-1e+2", -1, 2, 5);
checkParseDecimalFloat("1.1e+1", 11, 0, 6);
}

/// Positive sign with no digits is still an error.
function testParseLiteralDecimalFloatPositiveENoDigits() external pure {
checkParseDecimalFloatFail("1e+", MalformedExponentDigits.selector, 3);
checkParseDecimalFloatFail("0.0e+", MalformedExponentDigits.selector, 5);
}

/// Negative e with no digits is an error.
function testParseLiteralDecimalFloatNegativeE() external pure {
checkParseDecimalFloatFail("0.0e-", MalformedExponentDigits.selector, 5);
Expand Down
Loading