Skip to content

Commit c36baf9

Browse files
authored
Merge 642060a into 903c6b6
2 parents 903c6b6 + 642060a commit c36baf9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) {
215215
UNIT_ASSERT(FromStringEx("-1e-99", 10, 2) == 0);
216216
UNIT_ASSERT(FromStringEx("-510e-3", 1, 0) == -1);
217217
UNIT_ASSERT(FromStringEx("+99E3", 5, 0) == 99000);
218+
UNIT_ASSERT(FromStringEx("2.1E-130", 35, 2) == 0);
219+
UNIT_ASSERT(FromStringEx("2.1E0", 35, 2) == 210);
218220
}
219221

220222
Y_UNIT_TEST(TestFormStringExInvalidValues) {
@@ -225,7 +227,6 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) {
225227

226228
UNIT_ASSERT(IsError(FromStringEx("E2", 35, 15))); // empty
227229
UNIT_ASSERT(IsError(FromStringEx("E2E4", 35, 15))); // empty
228-
UNIT_ASSERT(IsError(FromStringEx("12E0", 35, 15))); // zero isn't avail
229230
UNIT_ASSERT(IsError(FromStringEx("NANE5", 35, 15))); // nan with exp
230231
}
231232

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

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

78
namespace NYql {
89
namespace NDecimal {
910

1011
static const TUint128 Ten(10U);
1112

1213
TUint128 GetDivider(ui8 scale) {
14+
if (scale > MaxPrecision) {
15+
return Inf();
16+
}
17+
1318
TUint128 d(1U);
1419
while (scale--)
1520
d *= Ten;
@@ -215,8 +220,13 @@ TInt128 FromStringEx(const TStringBuf& str, ui8 precision, ui8 scale) {
215220
if (!len)
216221
return Err();
217222

218-
const auto exp = std::atoi(++ptr);
219-
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())
220230
return Err();
221231

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

0 commit comments

Comments
 (0)