Skip to content

Commit 642060a

Browse files
committed
e0
1 parent 1853a74 commit 642060a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) {
216216
UNIT_ASSERT(FromStringEx("-510e-3", 1, 0) == -1);
217217
UNIT_ASSERT(FromStringEx("+99E3", 5, 0) == 99000);
218218
UNIT_ASSERT(FromStringEx("2.1E-130", 35, 2) == 0);
219+
UNIT_ASSERT(FromStringEx("2.1E0", 35, 2) == 210);
219220
}
220221

221222
Y_UNIT_TEST(TestFormStringExInvalidValues) {
@@ -226,7 +227,6 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) {
226227

227228
UNIT_ASSERT(IsError(FromStringEx("E2", 35, 15))); // empty
228229
UNIT_ASSERT(IsError(FromStringEx("E2E4", 35, 15))); // empty
229-
UNIT_ASSERT(IsError(FromStringEx("12E0", 35, 15))); // zero isn't avail
230230
UNIT_ASSERT(IsError(FromStringEx("NANE5", 35, 15))); // nan with exp
231231
}
232232

ydb/library/yql/public/decimal/yql_decimal.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstring>
44
#include <ostream>
55
#include <string>
6+
#include <charconv>
67

78
namespace NYql {
89
namespace NDecimal {
@@ -219,8 +220,13 @@ TInt128 FromStringEx(const TStringBuf& str, ui8 precision, ui8 scale) {
219220
if (!len)
220221
return Err();
221222

222-
const auto exp = std::atoi(++ptr);
223-
if (!exp)
223+
++ptr;
224+
if (ptr != s + str.size() && *ptr == '+') {
225+
++ptr;
226+
}
227+
228+
int exp;
229+
if (std::from_chars(ptr, s + str.size(), exp).ec != std::errc())
224230
return Err();
225231

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

0 commit comments

Comments
 (0)