Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstn committed Oct 29, 2024
1 parent 642060a commit af4df79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) {
UNIT_ASSERT(IsError(FromStringEx("E2", 35, 15))); // empty
UNIT_ASSERT(IsError(FromStringEx("E2E4", 35, 15))); // empty
UNIT_ASSERT(IsError(FromStringEx("NANE5", 35, 15))); // nan with exp
UNIT_ASSERT(IsError(FromStringEx("2.1E0X", 35, 2))); // not fully parsed exp
UNIT_ASSERT(IsError(FromStringEx("2.1E+-1", 35, 2))); // two signs
}

Y_UNIT_TEST(TestSpecialAsString) {
Expand Down
5 changes: 4 additions & 1 deletion ydb/library/yql/public/decimal/yql_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ TInt128 FromStringEx(const TStringBuf& str, ui8 precision, ui8 scale) {
++ptr;
if (ptr != s + str.size() && *ptr == '+') {
++ptr;
if (ptr != s + str.size() && *ptr == '-')
return Err();
}

int exp;
if (std::from_chars(ptr, s + str.size(), exp).ec != std::errc())
auto [finish, ec] = std::from_chars(ptr, s + str.size(), exp);
if (ec != std::errc() || finish != s + str.size())
return Err();

const int p = precision, s = int(scale) + exp;
Expand Down

0 comments on commit af4df79

Please sign in to comment.