@@ -32,7 +32,7 @@ bool IsNormal(TInt128 v) {
32
32
}
33
33
34
34
const char * ToString (TInt128 val, ui8 precision, ui8 scale) {
35
- if (! precision || precision > MaxPrecision || scale > precision) {
35
+ if (precision == 0 || precision > MaxPrecision || scale > precision) {
36
36
return " " ;
37
37
}
38
38
@@ -47,7 +47,7 @@ const char* ToString(TInt128 val, ui8 precision, ui8 scale) {
47
47
return nullptr ;
48
48
}
49
49
50
- if (! val) {
50
+ if (val == 0 ) {
51
51
return " 0" ;
52
52
}
53
53
@@ -63,9 +63,10 @@ const char* ToString(TInt128 val, ui8 precision, ui8 scale) {
63
63
auto s = end;
64
64
65
65
do {
66
- if (! precision-- ) {
66
+ if (precision == 0 ) {
67
67
return " " ;
68
68
}
69
+ --precision;
69
70
70
71
71
72
const auto digit = ui8 (v % Ten);
@@ -80,9 +81,10 @@ const char* ToString(TInt128 val, ui8 precision, ui8 scale) {
80
81
81
82
if (scale) {
82
83
do {
83
- if (! precision-- ) {
84
+ if (precision == 0 ) {
84
85
return nullptr ;
85
86
}
87
+ --precision;
86
88
87
89
*--s = ' 0' ;
88
90
} while (--scale);
@@ -119,7 +121,7 @@ TInt128 FromString(const std::string_view& str, ui8 precision, ui8 scale) {
119
121
auto s = str.data ();
120
122
auto l = str.size ();
121
123
122
- if (!s || !l )
124
+ if (s == nullptr || l == 0 )
123
125
return Err ();
124
126
125
127
const bool neg = ' -' == *s;
@@ -138,7 +140,7 @@ TInt128 FromString(const std::string_view& str, ui8 precision, ui8 scale) {
138
140
TUint128 v = 0U ;
139
141
auto integral = precision - scale;
140
142
141
- for (bool dot = false ; l; --l) {
143
+ for (bool dot = false ; l > 0 ; --l) {
142
144
if (*s == ' .' ) {
143
145
if (dot)
144
146
return Err ();
@@ -162,19 +164,23 @@ TInt128 FromString(const std::string_view& str, ui8 precision, ui8 scale) {
162
164
v *= Ten;
163
165
v += c - ' 0' ;
164
166
165
- if (!dot && v && !integral--) {
166
- return neg ? -Inf () : Inf ();
167
+ if (!dot && v > 0 ) {
168
+ if (integral == 0 ) {
169
+ return neg ? -Inf () : Inf ();
170
+ }
171
+ --integral;
167
172
}
168
173
}
169
174
170
- if (l--) {
175
+ if (l > 0 ) {
176
+ --l;
171
177
const char c = *s++;
172
178
if (!std::isdigit (c))
173
179
return Err ();
174
180
175
181
bool plus = c > ' 5' ;
176
182
if (!plus && c == ' 5' ) {
177
- for (plus = v & 1 ; !plus && l; --l) {
183
+ for (plus = v & 1 ; !plus && l > 0 ; --l) {
178
184
const char c = *s++;
179
185
if (!std::isdigit (c))
180
186
return Err ();
@@ -183,17 +189,21 @@ TInt128 FromString(const std::string_view& str, ui8 precision, ui8 scale) {
183
189
}
184
190
}
185
191
186
- while (l--)
192
+ while (l > 0 ) {
193
+ --l;
187
194
if (!std::isdigit (*s++))
188
195
return Err ();
196
+ }
189
197
190
198
if (plus)
191
199
if (++v >= GetDivider (precision))
192
200
v = Inf ();
193
201
}
194
202
195
- while (scale--)
203
+ while (scale > 0 ) {
204
+ --scale;
196
205
v *= Ten;
206
+ }
197
207
198
208
return neg ? -v : v;
199
209
}
@@ -209,7 +219,7 @@ bool IsValid(const std::string_view& str) {
209
219
auto s = str.data ();
210
220
auto l = str.size ();
211
221
212
- if (!s || !l )
222
+ if (s == nullptr || l == 0 )
213
223
return false ;
214
224
215
225
if (' -' == *s || ' +' == *s) {
@@ -221,7 +231,7 @@ bool IsValid(const std::string_view& str) {
221
231
return true ;
222
232
}
223
233
224
- for (bool dot = false ; l--; ) {
234
+ for (bool dot = false ; l > 0 ; l-- ) {
225
235
const char c = *s++;
226
236
if (c == ' .' ) {
227
237
if (dot)
0 commit comments