Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/external/abseil-cpp~/absl/strings/numbers.cc
Line
Count
Source
1
// Copyright 2017 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// This file contains string processing functions related to
16
// numeric values.
17
18
#include "absl/strings/numbers.h"
19
20
#include <algorithm>
21
#include <array>
22
#include <cassert>
23
#include <cfloat>  // for DBL_DIG and FLT_DIG
24
#include <cmath>   // for HUGE_VAL
25
#include <cstdint>
26
#include <cstdio>
27
#include <cstdlib>
28
#include <cstring>
29
#include <iterator>
30
#include <limits>
31
#include <system_error>  // NOLINT(build/c++11)
32
#include <utility>
33
34
#include "absl/base/attributes.h"
35
#include "absl/base/config.h"
36
#include "absl/base/internal/endian.h"
37
#include "absl/base/internal/raw_logging.h"
38
#include "absl/base/nullability.h"
39
#include "absl/base/optimization.h"
40
#include "absl/numeric/bits.h"
41
#include "absl/numeric/int128.h"
42
#include "absl/strings/ascii.h"
43
#include "absl/strings/charconv.h"
44
#include "absl/strings/match.h"
45
#include "absl/strings/string_view.h"
46
47
namespace absl {
48
ABSL_NAMESPACE_BEGIN
49
50
0
bool SimpleAtof(absl::string_view str, float* absl_nonnull out) {
51
0
  *out = 0.0;
52
0
  str = StripAsciiWhitespace(str);
53
0
  if (str.empty()) {
54
    // absl::from_chars doesn't accept empty strings.
55
0
    return false;
56
0
  }
57
  // std::from_chars doesn't accept an initial +, but SimpleAtof does, so if one
58
  // is present, skip it, while avoiding accepting "+-0" as valid.
59
0
  if (str[0] == '+') {
60
0
    str.remove_prefix(1);
61
0
    if (str.empty() || str[0] == '-') {
62
0
      return false;
63
0
    }
64
0
  }
65
0
  auto result = absl::from_chars(str.data(), str.data() + str.size(), *out);
66
0
  if (result.ec == std::errc::invalid_argument) {
67
0
    return false;
68
0
  }
69
0
  if (result.ptr != str.data() + str.size()) {
70
    // not all non-whitespace characters consumed
71
0
    return false;
72
0
  }
73
  // from_chars() with DR 3081's current wording will return max() on
74
  // overflow.  SimpleAtof returns infinity instead.
75
0
  if (result.ec == std::errc::result_out_of_range) {
76
0
    if (*out > 1.0) {
77
0
      *out = std::numeric_limits<float>::infinity();
78
0
    } else if (*out < -1.0) {
79
0
      *out = -std::numeric_limits<float>::infinity();
80
0
    }
81
0
  }
82
0
  return true;
83
0
}
84
85
80.4k
bool SimpleAtod(absl::string_view str, double* absl_nonnull out) {
86
80.4k
  *out = 0.0;
87
80.4k
  str = StripAsciiWhitespace(str);
88
80.4k
  if (str.empty()) {
89
    // absl::from_chars doesn't accept empty strings.
90
14
    return false;
91
14
  }
92
  // std::from_chars doesn't accept an initial +, but SimpleAtod does, so if one
93
  // is present, skip it, while avoiding accepting "+-0" as valid.
94
80.4k
  if (str[0] == '+') {
95
15
    str.remove_prefix(1);
96
15
    if (str.empty() || str[0] == '-') {
97
2
      return false;
98
2
    }
99
15
  }
100
80.4k
  auto result = absl::from_chars(str.data(), str.data() + str.size(), *out);
101
80.4k
  if (result.ec == std::errc::invalid_argument) {
102
106
    return false;
103
106
  }
104
80.3k
  if (result.ptr != str.data() + str.size()) {
105
    // not all non-whitespace characters consumed
106
561
    return false;
107
561
  }
108
  // from_chars() with DR 3081's current wording will return max() on
109
  // overflow.  SimpleAtod returns infinity instead.
110
79.8k
  if (result.ec == std::errc::result_out_of_range) {
111
5.85k
    if (*out > 1.0) {
112
3.76k
      *out = std::numeric_limits<double>::infinity();
113
3.76k
    } else if (*out < -1.0) {
114
737
      *out = -std::numeric_limits<double>::infinity();
115
737
    }
116
5.85k
  }
117
79.8k
  return true;
118
80.3k
}
119
120
0
bool SimpleAtob(absl::string_view str, bool* absl_nonnull out) {
121
0
  ABSL_RAW_CHECK(out != nullptr, "Output pointer must not be nullptr.");
122
0
  if (EqualsIgnoreCase(str, "true") || EqualsIgnoreCase(str, "t") ||
123
0
      EqualsIgnoreCase(str, "yes") || EqualsIgnoreCase(str, "y") ||
124
0
      EqualsIgnoreCase(str, "1")) {
125
0
    *out = true;
126
0
    return true;
127
0
  }
128
0
  if (EqualsIgnoreCase(str, "false") || EqualsIgnoreCase(str, "f") ||
129
0
      EqualsIgnoreCase(str, "no") || EqualsIgnoreCase(str, "n") ||
130
0
      EqualsIgnoreCase(str, "0")) {
131
0
    *out = false;
132
0
    return true;
133
0
  }
134
0
  return false;
135
0
}
136
137
// ----------------------------------------------------------------------
138
// FastIntToBuffer() overloads
139
//
140
// Like the Fast*ToBuffer() functions above, these are intended for speed.
141
// Unlike the Fast*ToBuffer() functions, however, these functions write
142
// their output to the beginning of the buffer.  The caller is responsible
143
// for ensuring that the buffer has enough space to hold the output.
144
//
145
// Returns a pointer to the end of the string (i.e. the null character
146
// terminating the string).
147
// ----------------------------------------------------------------------
148
149
namespace {
150
151
// Various routines to encode integers to strings.
152
153
// We split data encodings into a group of 2 digits, 4 digits, 8 digits as
154
// it's easier to combine powers of two into scalar arithmetic.
155
156
// Previous implementation used a lookup table of 200 bytes for every 2 bytes
157
// and it was memory bound, any L1 cache miss would result in a much slower
158
// result. When benchmarking with a cache eviction rate of several percent,
159
// this implementation proved to be better.
160
161
// These constants represent '00', '0000' and '00000000' as ascii strings in
162
// integers. We can add these numbers if we encode to bytes from 0 to 9. as
163
// 'i' = '0' + i for 0 <= i <= 9.
164
constexpr uint32_t kTwoZeroBytes = 0x0101 * '0';
165
constexpr uint64_t kFourZeroBytes = 0x01010101 * '0';
166
constexpr uint64_t kEightZeroBytes = 0x0101010101010101ull * '0';
167
168
// * 103 / 1024 is a division by 10 for values from 0 to 99. It's also a
169
// division of a structure [k takes 2 bytes][m takes 2 bytes], then * 103 / 1024
170
// will be [k / 10][m / 10]. It allows parallel division.
171
constexpr uint64_t kDivisionBy10Mul = 103u;
172
constexpr uint64_t kDivisionBy10Div = 1 << 10;
173
174
// * 10486 / 1048576 is a division by 100 for values from 0 to 9999.
175
constexpr uint64_t kDivisionBy100Mul = 10486u;
176
constexpr uint64_t kDivisionBy100Div = 1 << 20;
177
178
// Encode functions write the ASCII output of input `n` to `out_str`.
179
4.16k
inline char* EncodeHundred(uint32_t n, char* absl_nonnull out_str) {
180
4.16k
  int num_digits = static_cast<int>(n - 10) >> 8;
181
4.16k
  uint32_t div10 = (n * kDivisionBy10Mul) / kDivisionBy10Div;
182
4.16k
  uint32_t mod10 = n - 10u * div10;
183
4.16k
  uint32_t base = kTwoZeroBytes + div10 + (mod10 << 8);
184
4.16k
  base >>= num_digits & 8;
185
4.16k
  little_endian::Store16(out_str, static_cast<uint16_t>(base));
186
4.16k
  return out_str + 2 + num_digits;
187
4.16k
}
188
189
60
inline char* EncodeTenThousand(uint32_t n, char* absl_nonnull out_str) {
190
  // We split lower 2 digits and upper 2 digits of n into 2 byte consecutive
191
  // blocks. 123 ->  [\0\1][\0\23]. We divide by 10 both blocks
192
  // (it's 1 division + zeroing upper bits), and compute modulo 10 as well "in
193
  // parallel". Then we combine both results to have both ASCII digits,
194
  // strip trailing zeros, add ASCII '0000' and return.
195
60
  uint32_t div100 = (n * kDivisionBy100Mul) / kDivisionBy100Div;
196
60
  uint32_t mod100 = n - 100ull * div100;
197
60
  uint32_t hundreds = (mod100 << 16) + div100;
198
60
  uint32_t tens = (hundreds * kDivisionBy10Mul) / kDivisionBy10Div;
199
60
  tens &= (0xFull << 16) | 0xFull;
200
60
  tens += (hundreds - 10ull * tens) << 8;
201
60
  ABSL_ASSUME(tens != 0);
202
  // The result can contain trailing zero bits, we need to strip them to a first
203
  // significant byte in a final representation. For example, for n = 123, we
204
  // have tens to have representation \0\1\2\3. We do `& -8` to round
205
  // to a multiple to 8 to strip zero bytes, not all zero bits.
206
  // countr_zero to help.
207
  // 0 minus 8 to make MSVC happy.
208
60
  uint32_t zeroes = static_cast<uint32_t>(absl::countr_zero(tens)) & (0 - 8u);
209
60
  tens += kFourZeroBytes;
210
60
  tens >>= zeroes;
211
60
  little_endian::Store32(out_str, tens);
212
60
  return out_str + sizeof(tens) - zeroes / 8;
213
60
}
214
215
// Helper function to produce an ASCII representation of `i`.
216
//
217
// Function returns an 8-byte integer which when summed with `kEightZeroBytes`,
218
// can be treated as a printable buffer with ascii representation of `i`,
219
// possibly with leading zeros.
220
//
221
// Example:
222
//
223
//  uint64_t buffer = PrepareEightDigits(102030) + kEightZeroBytes;
224
//  char* ascii = reinterpret_cast<char*>(&buffer);
225
//  // Note two leading zeros:
226
//  EXPECT_EQ(absl::string_view(ascii, 8), "00102030");
227
//
228
// Pre-condition: `i` must be less than 100000000.
229
191k
inline uint64_t PrepareEightDigits(uint32_t i) {
230
191k
  ABSL_ASSUME(i < 10000'0000);
231
  // Prepare 2 blocks of 4 digits "in parallel".
232
191k
  uint32_t hi = i / 10000;
233
191k
  uint32_t lo = i % 10000;
234
191k
  uint64_t merged = hi | (uint64_t{lo} << 32);
235
191k
  uint64_t div100 = ((merged * kDivisionBy100Mul) / kDivisionBy100Div) &
236
191k
                    ((0x7Full << 32) | 0x7Full);
237
191k
  uint64_t mod100 = merged - 100ull * div100;
238
191k
  uint64_t hundreds = (mod100 << 16) + div100;
239
191k
  uint64_t tens = (hundreds * kDivisionBy10Mul) / kDivisionBy10Div;
240
191k
  tens &= (0xFull << 48) | (0xFull << 32) | (0xFull << 16) | 0xFull;
241
191k
  tens += (hundreds - 10ull * tens) << 8;
242
191k
  return tens;
243
191k
}
244
245
246
// Encodes v to buffer as 16 digits padded with leading zeros.
247
// Pre-condition: v must be < 10^16.
248
0
inline char* EncodePadded16(uint64_t v, char* absl_nonnull buffer) {
249
0
  constexpr uint64_t k1e8 = 100000000;
250
0
  uint32_t hi = static_cast<uint32_t>(v / k1e8);
251
0
  uint32_t lo = static_cast<uint32_t>(v % k1e8);
252
0
  little_endian::Store64(buffer, PrepareEightDigits(hi) + kEightZeroBytes);
253
0
  little_endian::Store64(buffer + 8, PrepareEightDigits(lo) + kEightZeroBytes);
254
0
  return buffer + 16;
255
0
}
256
257
inline ABSL_ATTRIBUTE_ALWAYS_INLINE char* absl_nonnull EncodeFullU32(
258
2.72M
    uint32_t n, char* absl_nonnull out_str) {
259
2.72M
  if (n < 10) {
260
2.53M
    *out_str = static_cast<char>('0' + n);
261
2.53M
    return out_str + 1;
262
2.53M
  }
263
191k
  if (n < 100'000'000) {
264
187k
    uint64_t bottom = PrepareEightDigits(n);
265
187k
    ABSL_ASSUME(bottom != 0);
266
    // 0 minus 8 to make MSVC happy.
267
187k
    uint32_t zeroes =
268
187k
        static_cast<uint32_t>(absl::countr_zero(bottom)) & (0 - 8u);
269
187k
    little_endian::Store64(out_str, (bottom + kEightZeroBytes) >> zeroes);
270
187k
    return out_str + sizeof(bottom) - zeroes / 8;
271
187k
  }
272
4.16k
  uint32_t div08 = n / 100'000'000;
273
4.16k
  uint32_t mod08 = n % 100'000'000;
274
4.16k
  uint64_t bottom = PrepareEightDigits(mod08) + kEightZeroBytes;
275
4.16k
  out_str = EncodeHundred(div08, out_str);
276
4.16k
  little_endian::Store64(out_str, bottom);
277
4.16k
  return out_str + sizeof(bottom);
278
191k
}
279
280
inline ABSL_ATTRIBUTE_ALWAYS_INLINE char* absl_nonnull EncodeFullU64(
281
2.33M
    uint64_t i, char* absl_nonnull buffer) {
282
2.33M
  if (i <= std::numeric_limits<uint32_t>::max()) {
283
2.33M
    return EncodeFullU32(static_cast<uint32_t>(i), buffer);
284
2.33M
  }
285
185
  uint32_t mod08;
286
185
  if (i < 1'0000'0000'0000'0000ull) {
287
125
    uint32_t div08 = static_cast<uint32_t>(i / 100'000'000ull);
288
125
    mod08 = static_cast<uint32_t>(i % 100'000'000ull);
289
125
    buffer = EncodeFullU32(div08, buffer);
290
125
  } else {
291
60
    uint64_t div08 = i / 100'000'000ull;
292
60
    mod08 = static_cast<uint32_t>(i % 100'000'000ull);
293
60
    uint32_t div016 = static_cast<uint32_t>(div08 / 100'000'000ull);
294
60
    uint32_t div08mod08 = static_cast<uint32_t>(div08 % 100'000'000ull);
295
60
    uint64_t mid_result = PrepareEightDigits(div08mod08) + kEightZeroBytes;
296
60
    buffer = EncodeTenThousand(div016, buffer);
297
60
    little_endian::Store64(buffer, mid_result);
298
60
    buffer += sizeof(mid_result);
299
60
  }
300
185
  uint64_t mod_result = PrepareEightDigits(mod08) + kEightZeroBytes;
301
185
  little_endian::Store64(buffer, mod_result);
302
185
  return buffer + sizeof(mod_result);
303
2.33M
}
304
305
inline ABSL_ATTRIBUTE_ALWAYS_INLINE char* absl_nonnull EncodeFullU128(
306
0
    uint128 i, char* absl_nonnull buffer) {
307
0
  if (absl::Uint128High64(i) == 0) {
308
0
    return EncodeFullU64(absl::Uint128Low64(i), buffer);
309
0
  }
310
  // We divide the number into 16-digit chunks because `EncodePadded16` is
311
  // optimized to handle 16 digits at a time (as two 8-digit chunks).
312
0
  constexpr uint64_t k1e16 = uint64_t{10'000'000'000'000'000};
313
0
  uint128 high = i / k1e16;
314
0
  uint64_t low = absl::Uint128Low64(i % k1e16);
315
0
  uint64_t mid = absl::Uint128Low64(high % k1e16);
316
0
  high /= k1e16;
317
318
0
  if (high == 0) {
319
0
    buffer = EncodeFullU64(mid, buffer);
320
0
    buffer = EncodePadded16(low, buffer);
321
0
  } else {
322
0
    buffer = EncodeFullU64(absl::Uint128Low64(high), buffer);
323
0
    buffer = EncodePadded16(mid, buffer);
324
0
    buffer = EncodePadded16(low, buffer);
325
0
  }
326
0
  return buffer;
327
0
}
328
329
}  // namespace
330
331
7.42k
void numbers_internal::PutTwoDigits(uint32_t i, char* absl_nonnull buf) {
332
7.42k
  assert(i < 100);
333
7.42k
  uint32_t base = kTwoZeroBytes;
334
7.42k
  uint32_t div10 = (i * kDivisionBy10Mul) / kDivisionBy10Div;
335
7.42k
  uint32_t mod10 = i - 10u * div10;
336
7.42k
  base += div10 + (mod10 << 8);
337
7.42k
  little_endian::Store16(buf, static_cast<uint16_t>(base));
338
7.42k
}
339
340
char* absl_nonnull numbers_internal::FastIntToBuffer(
341
385k
    uint32_t n, char* absl_nonnull out_str) {
342
385k
  out_str = EncodeFullU32(n, out_str);
343
385k
  *out_str = '\0';
344
385k
  return out_str;
345
385k
}
346
347
char* absl_nonnull numbers_internal::FastIntToBuffer(
348
4.43k
    int32_t i, char* absl_nonnull buffer) {
349
4.43k
  uint32_t u = static_cast<uint32_t>(i);
350
4.43k
  if (i < 0) {
351
0
    *buffer++ = '-';
352
    // We need to do the negation in modular (i.e., "unsigned")
353
    // arithmetic; MSVC++ apparently warns for plain "-u", so
354
    // we write the equivalent expression "0 - u" instead.
355
0
    u = 0 - u;
356
0
  }
357
4.43k
  buffer = EncodeFullU32(u, buffer);
358
4.43k
  *buffer = '\0';
359
4.43k
  return buffer;
360
4.43k
}
361
362
char* absl_nonnull numbers_internal::FastIntToBuffer(
363
2.33M
    uint64_t i, char* absl_nonnull buffer) {
364
2.33M
  buffer = EncodeFullU64(i, buffer);
365
2.33M
  *buffer = '\0';
366
2.33M
  return buffer;
367
2.33M
}
368
369
char* absl_nonnull numbers_internal::FastIntToBuffer(
370
1.19k
    int64_t i, char* absl_nonnull buffer) {
371
1.19k
  uint64_t u = static_cast<uint64_t>(i);
372
1.19k
  if (i < 0) {
373
200
    *buffer++ = '-';
374
    // We need to do the negation in modular (i.e., "unsigned")
375
    // arithmetic; MSVC++ apparently warns for plain "-u", so
376
    // we write the equivalent expression "0 - u" instead.
377
200
    u = 0 - u;
378
200
  }
379
1.19k
  buffer = EncodeFullU64(u, buffer);
380
1.19k
  *buffer = '\0';
381
1.19k
  return buffer;
382
1.19k
}
383
384
char* absl_nonnull numbers_internal::FastIntToBuffer(
385
0
    uint128 i, char* absl_nonnull buffer) {
386
0
  buffer = EncodeFullU128(i, buffer);
387
0
  *buffer = '\0';
388
0
  return buffer;
389
0
}
390
391
char* absl_nonnull numbers_internal::FastIntToBuffer(
392
0
    int128 i, char* absl_nonnull buffer) {
393
0
  uint128 u = static_cast<uint128>(i);
394
0
  if (i < 0) {
395
0
    *buffer++ = '-';
396
0
    u = -u;
397
0
  }
398
0
  buffer = EncodeFullU128(u, buffer);
399
0
  *buffer = '\0';
400
0
  return buffer;
401
0
}
402
403
// Given a 128-bit number expressed as a pair of uint64_t, high half first,
404
// return that number multiplied by the given 32-bit value.  If the result is
405
// too large to fit in a 128-bit number, divide it by 2 until it fits.
406
static std::pair<uint64_t, uint64_t> Mul32(std::pair<uint64_t, uint64_t> num,
407
2.46k
                                           uint32_t mul) {
408
2.46k
  uint64_t bits0_31 = num.second & 0xFFFFFFFF;
409
2.46k
  uint64_t bits32_63 = num.second >> 32;
410
2.46k
  uint64_t bits64_95 = num.first & 0xFFFFFFFF;
411
2.46k
  uint64_t bits96_127 = num.first >> 32;
412
413
  // The picture so far: each of these 64-bit values has only the lower 32 bits
414
  // filled in.
415
  // bits96_127:          [ 00000000 xxxxxxxx ]
416
  // bits64_95:                    [ 00000000 xxxxxxxx ]
417
  // bits32_63:                             [ 00000000 xxxxxxxx ]
418
  // bits0_31:                                       [ 00000000 xxxxxxxx ]
419
420
2.46k
  bits0_31 *= mul;
421
2.46k
  bits32_63 *= mul;
422
2.46k
  bits64_95 *= mul;
423
2.46k
  bits96_127 *= mul;
424
425
  // Now the top halves may also have value, though all 64 of their bits will
426
  // never be set at the same time, since they are a result of a 32x32 bit
427
  // multiply.  This makes the carry calculation slightly easier.
428
  // bits96_127:          [ mmmmmmmm | mmmmmmmm ]
429
  // bits64_95:                    [ | mmmmmmmm mmmmmmmm | ]
430
  // bits32_63:                      |        [ mmmmmmmm | mmmmmmmm ]
431
  // bits0_31:                       |                 [ | mmmmmmmm mmmmmmmm ]
432
  // eventually:        [ bits128_up | ...bits64_127.... | ..bits0_63... ]
433
434
2.46k
  uint64_t bits0_63 = bits0_31 + (bits32_63 << 32);
435
2.46k
  uint64_t bits64_127 = bits64_95 + (bits96_127 << 32) + (bits32_63 >> 32) +
436
2.46k
                        (bits0_63 < bits0_31);
437
2.46k
  uint64_t bits128_up = (bits96_127 >> 32) + (bits64_127 < bits64_95);
438
2.46k
  if (bits128_up == 0) return {bits64_127, bits0_63};
439
440
2.01k
  auto shift = static_cast<unsigned>(bit_width(bits128_up));
441
2.01k
  uint64_t lo = (bits0_63 >> shift) + (bits64_127 << (64 - shift));
442
2.01k
  uint64_t hi = (bits64_127 >> shift) + (bits128_up << (64 - shift));
443
2.01k
  return {hi, lo};
444
2.46k
}
445
446
// Compute num * 5 ^ expfive, and return the first 128 bits of the result,
447
// where the first bit is always a one.  So PowFive(1, 0) starts 0b100000,
448
// PowFive(1, 1) starts 0b101000, PowFive(1, 2) starts 0b110010, etc.
449
599
static std::pair<uint64_t, uint64_t> PowFive(uint64_t num, int expfive) {
450
599
  std::pair<uint64_t, uint64_t> result = {num, 0};
451
2.46k
  while (expfive >= 13) {
452
    // 5^13 is the highest power of five that will fit in a 32-bit integer.
453
1.86k
    result = Mul32(result, 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5);
454
1.86k
    expfive -= 13;
455
1.86k
  }
456
599
  constexpr uint32_t powers_of_five[13] = {
457
599
      1,
458
599
      5,
459
599
      5 * 5,
460
599
      5 * 5 * 5,
461
599
      5 * 5 * 5 * 5,
462
599
      5 * 5 * 5 * 5 * 5,
463
599
      5 * 5 * 5 * 5 * 5 * 5,
464
599
      5 * 5 * 5 * 5 * 5 * 5 * 5,
465
599
      5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
466
599
      5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
467
599
      5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
468
599
      5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
469
599
      5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5};
470
599
  result = Mul32(result, powers_of_five[expfive & 15]);
471
599
  int shift = countl_zero(result.first);
472
599
  if (shift != 0) {
473
237
    result.first = (result.first << shift) + (result.second >> (64 - shift));
474
237
    result.second = (result.second << shift);
475
237
  }
476
599
  return result;
477
599
}
478
479
struct ExpDigits {
480
  int32_t exponent;
481
  char digits[6];
482
};
483
484
// SplitToSix converts value, a positive double-precision floating-point number,
485
// into a base-10 exponent and 6 ASCII digits, where the first digit is never
486
// zero.  For example, SplitToSix(1) returns an exponent of zero and a digits
487
// array of {'1', '0', '0', '0', '0', '0'}.  If value is exactly halfway between
488
// two possible representations, e.g. value = 100000.5, then "round to even" is
489
// performed.
490
2.10k
static ExpDigits SplitToSix(const double value) {
491
2.10k
  ExpDigits exp_dig;
492
2.10k
  int exp = 5;
493
2.10k
  double d = value;
494
  // First step: calculate a close approximation of the output, where the
495
  // value d will be between 100,000 and 999,999, representing the digits
496
  // in the output ASCII array, and exp is the base-10 exponent.  It would be
497
  // faster to use a table here, and to look up the base-2 exponent of value,
498
  // however value is an IEEE-754 64-bit number, so the table would have 2,000
499
  // entries, which is not cache-friendly.
500
2.10k
  if (d >= 999999.5) {
501
738
    if (d >= 1e+261) exp += 256, d *= 1e-256;
502
738
    if (d >= 1e+133) exp += 128, d *= 1e-128;
503
738
    if (d >= 1e+69) exp += 64, d *= 1e-64;
504
738
    if (d >= 1e+37) exp += 32, d *= 1e-32;
505
738
    if (d >= 1e+21) exp += 16, d *= 1e-16;
506
738
    if (d >= 1e+13) exp += 8, d *= 1e-8;
507
738
    if (d >= 1e+9) exp += 4, d *= 1e-4;
508
738
    if (d >= 1e+7) exp += 2, d *= 1e-2;
509
738
    if (d >= 1e+6) exp += 1, d *= 1e-1;
510
1.36k
  } else {
511
1.36k
    if (d < 1e-250) exp -= 256, d *= 1e256;
512
1.36k
    if (d < 1e-122) exp -= 128, d *= 1e128;
513
1.36k
    if (d < 1e-58) exp -= 64, d *= 1e64;
514
1.36k
    if (d < 1e-26) exp -= 32, d *= 1e32;
515
1.36k
    if (d < 1e-10) exp -= 16, d *= 1e16;
516
1.36k
    if (d < 1e-2) exp -= 8, d *= 1e8;
517
1.36k
    if (d < 1e+2) exp -= 4, d *= 1e4;
518
1.36k
    if (d < 1e+4) exp -= 2, d *= 1e2;
519
1.36k
    if (d < 1e+5) exp -= 1, d *= 1e1;
520
1.36k
  }
521
  // At this point, d is in the range [99999.5..999999.5) and exp is in the
522
  // range [-324..308]. Since we need to round d up, we want to add a half
523
  // and truncate.
524
  // However, the technique above may have lost some precision, due to its
525
  // repeated multiplication by constants that each may be off by half a bit
526
  // of precision.  This only matters if we're close to the edge though.
527
  // Since we'd like to know if the fractional part of d is close to a half,
528
  // we multiply it by 65536 and see if the fractional part is close to 32768.
529
  // (The number doesn't have to be a power of two,but powers of two are faster)
530
2.10k
  uint64_t d64k = static_cast<uint64_t>(d * 65536);
531
2.10k
  uint32_t dddddd;  // A 6-digit decimal integer.
532
2.10k
  if ((d64k % 65536) == 32767 || (d64k % 65536) == 32768) {
533
    // OK, it's fairly likely that precision was lost above, which is
534
    // not a surprise given only 52 mantissa bits are available.  Therefore
535
    // redo the calculation using 128-bit numbers.  (64 bits are not enough).
536
537
    // Start out with digits rounded down; maybe add one below.
538
430
    dddddd = static_cast<uint32_t>(d64k / 65536);
539
540
    // mantissa is a 64-bit integer representing M.mmm... * 2^63.  The actual
541
    // value we're representing, of course, is M.mmm... * 2^exp2.
542
430
    int exp2;
543
430
    double m = std::frexp(value, &exp2);
544
430
    uint64_t mantissa =
545
430
        static_cast<uint64_t>(m * (32768.0 * 65536.0 * 65536.0 * 65536.0));
546
    // std::frexp returns an m value in the range [0.5, 1.0), however we
547
    // can't multiply it by 2^64 and convert to an integer because some FPUs
548
    // throw an exception when converting an number higher than 2^63 into an
549
    // integer - even an unsigned 64-bit integer!  Fortunately it doesn't matter
550
    // since m only has 52 significant bits anyway.
551
430
    mantissa <<= 1;
552
430
    exp2 -= 64;  // not needed, but nice for debugging
553
554
    // OK, we are here to compare:
555
    //     (dddddd + 0.5) * 10^(exp-5)  vs.  mantissa * 2^exp2
556
    // so we can round up dddddd if appropriate.  Those values span the full
557
    // range of 600 orders of magnitude of IEE 64-bit floating-point.
558
    // Fortunately, we already know they are very close, so we don't need to
559
    // track the base-2 exponent of both sides.  This greatly simplifies the
560
    // the math since the 2^exp2 calculation is unnecessary and the power-of-10
561
    // calculation can become a power-of-5 instead.
562
563
430
    std::pair<uint64_t, uint64_t> edge, val;
564
430
    if (exp >= 6) {
565
      // Compare (dddddd + 0.5) * 5 ^ (exp - 5) to mantissa
566
      // Since we're tossing powers of two, 2 * dddddd + 1 is the
567
      // same as dddddd + 0.5
568
261
      edge = PowFive(2 * dddddd + 1, exp - 5);
569
570
261
      val.first = mantissa;
571
261
      val.second = 0;
572
261
    } else {
573
      // We can't compare (dddddd + 0.5) * 5 ^ (exp - 5) to mantissa as we did
574
      // above because (exp - 5) is negative.  So we compare (dddddd + 0.5) to
575
      // mantissa * 5 ^ (5 - exp)
576
169
      edge = PowFive(2 * dddddd + 1, 0);
577
578
169
      val = PowFive(mantissa, 5 - exp);
579
169
    }
580
    // printf("exp=%d %016lx %016lx vs %016lx %016lx\n", exp, val.first,
581
    //        val.second, edge.first, edge.second);
582
430
    if (val > edge) {
583
97
      dddddd++;
584
333
    } else if (val == edge) {
585
59
      dddddd += (dddddd & 1);
586
59
    }
587
1.67k
  } else {
588
    // Here, we are not close to the edge.
589
1.67k
    dddddd = static_cast<uint32_t>((d64k + 32768) / 65536);
590
1.67k
  }
591
2.10k
  if (dddddd == 1000000) {
592
38
    dddddd = 100000;
593
38
    exp += 1;
594
38
  }
595
2.10k
  exp_dig.exponent = exp;
596
597
2.10k
  uint32_t two_digits = dddddd / 10000;
598
2.10k
  dddddd -= two_digits * 10000;
599
2.10k
  numbers_internal::PutTwoDigits(two_digits, &exp_dig.digits[0]);
600
601
2.10k
  two_digits = dddddd / 100;
602
2.10k
  dddddd -= two_digits * 100;
603
2.10k
  numbers_internal::PutTwoDigits(two_digits, &exp_dig.digits[2]);
604
605
2.10k
  numbers_internal::PutTwoDigits(dddddd, &exp_dig.digits[4]);
606
2.10k
  return exp_dig;
607
2.10k
}
608
609
// Helper function for fast formatting of floating-point.
610
// The result is the same as "%g", a.k.a. "%.6g".
611
size_t numbers_internal::SixDigitsToBuffer(double d,
612
2.22k
                                           char* absl_nonnull const buffer) {
613
2.22k
  static_assert(std::numeric_limits<float>::is_iec559,
614
2.22k
                "IEEE-754/IEC-559 support only");
615
616
2.22k
  char* out = buffer;  // we write data to out, incrementing as we go, but
617
                       // FloatToBuffer always returns the address of the buffer
618
                       // passed in.
619
620
2.22k
  if (std::isnan(d)) {
621
0
    strcpy(out, "nan");  // NOLINT(runtime/printf)
622
0
    return 3;
623
0
  }
624
2.22k
  if (d == 0) {  // +0 and -0 are handled here
625
117
    if (std::signbit(d)) *out++ = '-';
626
117
    *out++ = '0';
627
117
    *out = 0;
628
117
    return static_cast<size_t>(out - buffer);
629
117
  }
630
2.10k
  if (d < 0) {
631
145
    *out++ = '-';
632
145
    d = -d;
633
145
  }
634
2.10k
  if (d > std::numeric_limits<double>::max()) {
635
0
    strcpy(out, "inf");  // NOLINT(runtime/printf)
636
0
    return static_cast<size_t>(out + 3 - buffer);
637
0
  }
638
639
2.10k
  auto exp_dig = SplitToSix(d);
640
2.10k
  int exp = exp_dig.exponent;
641
2.10k
  const char* digits = exp_dig.digits;
642
2.10k
  out[0] = '0';
643
2.10k
  out[1] = '.';
644
2.10k
  switch (exp) {
645
44
    case 5:
646
44
      memcpy(out, &digits[0], 6), out += 6;
647
44
      *out = 0;
648
44
      return static_cast<size_t>(out - buffer);
649
101
    case 4:
650
101
      memcpy(out, &digits[0], 5), out += 5;
651
101
      if (digits[5] != '0') {
652
44
        *out++ = '.';
653
44
        *out++ = digits[5];
654
44
      }
655
101
      *out = 0;
656
101
      return static_cast<size_t>(out - buffer);
657
120
    case 3:
658
120
      memcpy(out, &digits[0], 4), out += 4;
659
120
      if ((digits[5] | digits[4]) != '0') {
660
70
        *out++ = '.';
661
70
        *out++ = digits[4];
662
70
        if (digits[5] != '0') *out++ = digits[5];
663
70
      }
664
120
      *out = 0;
665
120
      return static_cast<size_t>(out - buffer);
666
184
    case 2:
667
184
      memcpy(out, &digits[0], 3), out += 3;
668
184
      *out++ = '.';
669
184
      memcpy(out, &digits[3], 3);
670
184
      out += 3;
671
632
      while (out[-1] == '0') --out;
672
184
      if (out[-1] == '.') --out;
673
184
      *out = 0;
674
184
      return static_cast<size_t>(out - buffer);
675
173
    case 1:
676
173
      memcpy(out, &digits[0], 2), out += 2;
677
173
      *out++ = '.';
678
173
      memcpy(out, &digits[2], 4);
679
173
      out += 4;
680
730
      while (out[-1] == '0') --out;
681
173
      if (out[-1] == '.') --out;
682
173
      *out = 0;
683
173
      return static_cast<size_t>(out - buffer);
684
89
    case 0:
685
89
      memcpy(out, &digits[0], 1), out += 1;
686
89
      *out++ = '.';
687
89
      memcpy(out, &digits[1], 5);
688
89
      out += 5;
689
387
      while (out[-1] == '0') --out;
690
89
      if (out[-1] == '.') --out;
691
89
      *out = 0;
692
89
      return static_cast<size_t>(out - buffer);
693
84
    case -4:
694
84
      out[2] = '0';
695
84
      ++out;
696
84
      ABSL_FALLTHROUGH_INTENDED;
697
154
    case -3:
698
154
      out[2] = '0';
699
154
      ++out;
700
154
      ABSL_FALLTHROUGH_INTENDED;
701
197
    case -2:
702
197
      out[2] = '0';
703
197
      ++out;
704
197
      ABSL_FALLTHROUGH_INTENDED;
705
278
    case -1:
706
278
      out += 2;
707
278
      memcpy(out, &digits[0], 6);
708
278
      out += 6;
709
1.35k
      while (out[-1] == '0') --out;
710
278
      *out = 0;
711
278
      return static_cast<size_t>(out - buffer);
712
2.10k
  }
713
2.10k
  assert(exp < -4 || exp >= 6);
714
1.11k
  out[0] = digits[0];
715
1.11k
  assert(out[1] == '.');
716
1.11k
  out += 2;
717
1.11k
  memcpy(out, &digits[1], 5), out += 5;
718
3.34k
  while (out[-1] == '0') --out;
719
1.11k
  if (out[-1] == '.') --out;
720
1.11k
  *out++ = 'e';
721
1.11k
  if (exp > 0) {
722
738
    *out++ = '+';
723
738
  } else {
724
376
    *out++ = '-';
725
376
    exp = -exp;
726
376
  }
727
1.11k
  if (exp > 99) {
728
189
    int dig1 = exp / 100;
729
189
    exp -= dig1 * 100;
730
189
    *out++ = '0' + static_cast<char>(dig1);
731
189
  }
732
1.11k
  PutTwoDigits(static_cast<uint32_t>(exp), out);
733
1.11k
  out += 2;
734
1.11k
  *out = 0;
735
1.11k
  return static_cast<size_t>(out - buffer);
736
2.10k
}
737
738
namespace {
739
// Represents integer values of digits.
740
// Uses 36 to indicate an invalid character since we support
741
// bases up to 36.
742
static constexpr std::array<int8_t, 256> kAsciiToInt = {
743
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,  // 16 36s.
744
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
745
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 0,  1,  2,  3,  4,  5,
746
    6,  7,  8,  9,  36, 36, 36, 36, 36, 36, 36, 10, 11, 12, 13, 14, 15, 16, 17,
747
    18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
748
    36, 36, 36, 36, 36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
749
    24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36, 36, 36,
750
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
751
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
752
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
753
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
754
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
755
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
756
    36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36};
757
758
// Parse the sign and optional hex or oct prefix in text.
759
inline bool safe_parse_sign_and_base(
760
    absl::string_view* absl_nonnull text /*inout*/,
761
    int* absl_nonnull base_ptr /*inout*/,
762
774k
    bool* absl_nonnull negative_ptr /*output*/) {
763
774k
  if (text->data() == nullptr) {
764
0
    return false;
765
0
  }
766
767
774k
  const char* start = text->data();
768
774k
  const char* end = start + text->size();
769
774k
  int base = *base_ptr;
770
771
  // Consume whitespace.
772
774k
  while (start < end &&
773
774k
         absl::ascii_isspace(static_cast<unsigned char>(start[0]))) {
774
903
    ++start;
775
903
  }
776
775k
  while (start < end &&
777
775k
         absl::ascii_isspace(static_cast<unsigned char>(end[-1]))) {
778
1.00k
    --end;
779
1.00k
  }
780
774k
  if (start >= end) {
781
88
    return false;
782
88
  }
783
784
  // Consume sign.
785
774k
  *negative_ptr = (start[0] == '-');
786
774k
  if (*negative_ptr || start[0] == '+') {
787
19.4k
    ++start;
788
19.4k
    if (start >= end) {
789
108
      return false;
790
108
    }
791
19.4k
  }
792
793
  // Consume base-dependent prefix.
794
  //  base 0: "0x" -> base 16, "0" -> base 8, default -> base 10
795
  //  base 16: "0x" -> base 16
796
  // Also validate the base.
797
773k
  if (base == 0) {
798
0
    if (end - start >= 2 && start[0] == '0' &&
799
0
        (start[1] == 'x' || start[1] == 'X')) {
800
0
      base = 16;
801
0
      start += 2;
802
0
      if (start >= end) {
803
        // "0x" with no digits after is invalid.
804
0
        return false;
805
0
      }
806
0
    } else if (end - start >= 1 && start[0] == '0') {
807
0
      base = 8;
808
0
      start += 1;
809
0
    } else {
810
0
      base = 10;
811
0
    }
812
773k
  } else if (base == 16) {
813
6.35k
    if (end - start >= 2 && start[0] == '0' &&
814
6.35k
        (start[1] == 'x' || start[1] == 'X')) {
815
6.35k
      start += 2;
816
6.35k
      if (start >= end) {
817
        // "0x" with no digits after is invalid.
818
0
        return false;
819
0
      }
820
6.35k
    }
821
767k
  } else if (base >= 2 && base <= 36) {
822
    // okay
823
767k
  } else {
824
0
    return false;
825
0
  }
826
773k
  *text = absl::string_view(start, static_cast<size_t>(end - start));
827
773k
  *base_ptr = base;
828
773k
  return true;
829
773k
}
830
831
// Consume digits.
832
//
833
// The classic loop:
834
//
835
//   for each digit
836
//     value = value * base + digit
837
//   value *= sign
838
//
839
// The classic loop needs overflow checking.  It also fails on the most
840
// negative integer, -2147483648 in 32-bit two's complement representation.
841
//
842
// My improved loop:
843
//
844
//  if (!negative)
845
//    for each digit
846
//      value = value * base
847
//      value = value + digit
848
//  else
849
//    for each digit
850
//      value = value * base
851
//      value = value - digit
852
//
853
// Overflow checking becomes simple.
854
855
// Lookup tables per IntType:
856
// vmax/base and vmin/base are precomputed because division costs at least 8ns.
857
// TODO(junyer): Doing this per base instead (i.e. an array of structs, not a
858
// struct of arrays) would probably be better in terms of d-cache for the most
859
// commonly used bases.
860
template <typename IntType>
861
struct LookupTables {
862
  ABSL_CONST_INIT static const IntType kVmaxOverBase[];
863
  ABSL_CONST_INIT static const IntType kVminOverBase[];
864
};
865
866
// An array initializer macro for X/base where base in [0, 36].
867
// However, note that lookups for base in [0, 1] should never happen because
868
// base has been validated to be in [2, 36] by safe_parse_sign_and_base().
869
#define X_OVER_BASE_INITIALIZER(X)                                        \
870
  {                                                                       \
871
    0, 0, X / 2, X / 3, X / 4, X / 5, X / 6, X / 7, X / 8, X / 9, X / 10, \
872
        X / 11, X / 12, X / 13, X / 14, X / 15, X / 16, X / 17, X / 18,   \
873
        X / 19, X / 20, X / 21, X / 22, X / 23, X / 24, X / 25, X / 26,   \
874
        X / 27, X / 28, X / 29, X / 30, X / 31, X / 32, X / 33, X / 34,   \
875
        X / 35, X / 36,                                                   \
876
  }
877
878
// This kVmaxOverBase is generated with
879
//  for (int base = 2; base < 37; ++base) {
880
//    absl::uint128 max = std::numeric_limits<absl::uint128>::max();
881
//    auto result = max / base;
882
//    std::cout << "    MakeUint128(" << absl::Uint128High64(result) << "u, "
883
//              << absl::Uint128Low64(result) << "u),\n";
884
//  }
885
// See https://godbolt.org/z/aneYsb
886
//
887
// uint128& operator/=(uint128) is not constexpr, so hardcode the resulting
888
// array to avoid a static initializer.
889
template <>
890
ABSL_CONST_INIT const uint128 LookupTables<uint128>::kVmaxOverBase[] = {
891
    0,
892
    0,
893
    MakeUint128(9223372036854775807u, 18446744073709551615u),
894
    MakeUint128(6148914691236517205u, 6148914691236517205u),
895
    MakeUint128(4611686018427387903u, 18446744073709551615u),
896
    MakeUint128(3689348814741910323u, 3689348814741910323u),
897
    MakeUint128(3074457345618258602u, 12297829382473034410u),
898
    MakeUint128(2635249153387078802u, 5270498306774157604u),
899
    MakeUint128(2305843009213693951u, 18446744073709551615u),
900
    MakeUint128(2049638230412172401u, 14347467612885206812u),
901
    MakeUint128(1844674407370955161u, 11068046444225730969u),
902
    MakeUint128(1676976733973595601u, 8384883669867978007u),
903
    MakeUint128(1537228672809129301u, 6148914691236517205u),
904
    MakeUint128(1418980313362273201u, 4256940940086819603u),
905
    MakeUint128(1317624576693539401u, 2635249153387078802u),
906
    MakeUint128(1229782938247303441u, 1229782938247303441u),
907
    MakeUint128(1152921504606846975u, 18446744073709551615u),
908
    MakeUint128(1085102592571150095u, 1085102592571150095u),
909
    MakeUint128(1024819115206086200u, 16397105843297379214u),
910
    MakeUint128(970881267037344821u, 16504981539634861972u),
911
    MakeUint128(922337203685477580u, 14757395258967641292u),
912
    MakeUint128(878416384462359600u, 14054662151397753612u),
913
    MakeUint128(838488366986797800u, 13415813871788764811u),
914
    MakeUint128(802032351030850070u, 4812194106185100421u),
915
    MakeUint128(768614336404564650u, 12297829382473034410u),
916
    MakeUint128(737869762948382064u, 11805916207174113034u),
917
    MakeUint128(709490156681136600u, 11351842506898185609u),
918
    MakeUint128(683212743470724133u, 17080318586768103348u),
919
    MakeUint128(658812288346769700u, 10540996613548315209u),
920
    MakeUint128(636094623231363848u, 15266270957552732371u),
921
    MakeUint128(614891469123651720u, 9838263505978427528u),
922
    MakeUint128(595056260442243600u, 9520900167075897608u),
923
    MakeUint128(576460752303423487u, 18446744073709551615u),
924
    MakeUint128(558992244657865200u, 8943875914525843207u),
925
    MakeUint128(542551296285575047u, 9765923333140350855u),
926
    MakeUint128(527049830677415760u, 8432797290838652167u),
927
    MakeUint128(512409557603043100u, 8198552921648689607u),
928
};
929
930
// This kVmaxOverBase generated with
931
//   for (int base = 2; base < 37; ++base) {
932
//    absl::int128 max = std::numeric_limits<absl::int128>::max();
933
//    auto result = max / base;
934
//    std::cout << "\tMakeInt128(" << absl::Int128High64(result) << ", "
935
//              << absl::Int128Low64(result) << "u),\n";
936
//  }
937
// See https://godbolt.org/z/7djYWz
938
//
939
// int128& operator/=(int128) is not constexpr, so hardcode the resulting array
940
// to avoid a static initializer.
941
template <>
942
ABSL_CONST_INIT const int128 LookupTables<int128>::kVmaxOverBase[] = {
943
    0,
944
    0,
945
    MakeInt128(4611686018427387903, 18446744073709551615u),
946
    MakeInt128(3074457345618258602, 12297829382473034410u),
947
    MakeInt128(2305843009213693951, 18446744073709551615u),
948
    MakeInt128(1844674407370955161, 11068046444225730969u),
949
    MakeInt128(1537228672809129301, 6148914691236517205u),
950
    MakeInt128(1317624576693539401, 2635249153387078802u),
951
    MakeInt128(1152921504606846975, 18446744073709551615u),
952
    MakeInt128(1024819115206086200, 16397105843297379214u),
953
    MakeInt128(922337203685477580, 14757395258967641292u),
954
    MakeInt128(838488366986797800, 13415813871788764811u),
955
    MakeInt128(768614336404564650, 12297829382473034410u),
956
    MakeInt128(709490156681136600, 11351842506898185609u),
957
    MakeInt128(658812288346769700, 10540996613548315209u),
958
    MakeInt128(614891469123651720, 9838263505978427528u),
959
    MakeInt128(576460752303423487, 18446744073709551615u),
960
    MakeInt128(542551296285575047, 9765923333140350855u),
961
    MakeInt128(512409557603043100, 8198552921648689607u),
962
    MakeInt128(485440633518672410, 17475862806672206794u),
963
    MakeInt128(461168601842738790, 7378697629483820646u),
964
    MakeInt128(439208192231179800, 7027331075698876806u),
965
    MakeInt128(419244183493398900, 6707906935894382405u),
966
    MakeInt128(401016175515425035, 2406097053092550210u),
967
    MakeInt128(384307168202282325, 6148914691236517205u),
968
    MakeInt128(368934881474191032, 5902958103587056517u),
969
    MakeInt128(354745078340568300, 5675921253449092804u),
970
    MakeInt128(341606371735362066, 17763531330238827482u),
971
    MakeInt128(329406144173384850, 5270498306774157604u),
972
    MakeInt128(318047311615681924, 7633135478776366185u),
973
    MakeInt128(307445734561825860, 4919131752989213764u),
974
    MakeInt128(297528130221121800, 4760450083537948804u),
975
    MakeInt128(288230376151711743, 18446744073709551615u),
976
    MakeInt128(279496122328932600, 4471937957262921603u),
977
    MakeInt128(271275648142787523, 14106333703424951235u),
978
    MakeInt128(263524915338707880, 4216398645419326083u),
979
    MakeInt128(256204778801521550, 4099276460824344803u),
980
};
981
982
// This kVminOverBase generated with
983
//  for (int base = 2; base < 37; ++base) {
984
//    absl::int128 min = std::numeric_limits<absl::int128>::min();
985
//    auto result = min / base;
986
//    std::cout << "\tMakeInt128(" << absl::Int128High64(result) << ", "
987
//              << absl::Int128Low64(result) << "u),\n";
988
//  }
989
//
990
// See https://godbolt.org/z/7djYWz
991
//
992
// int128& operator/=(int128) is not constexpr, so hardcode the resulting array
993
// to avoid a static initializer.
994
template <>
995
ABSL_CONST_INIT const int128 LookupTables<int128>::kVminOverBase[] = {
996
    0,
997
    0,
998
    MakeInt128(-4611686018427387904, 0u),
999
    MakeInt128(-3074457345618258603, 6148914691236517206u),
1000
    MakeInt128(-2305843009213693952, 0u),
1001
    MakeInt128(-1844674407370955162, 7378697629483820647u),
1002
    MakeInt128(-1537228672809129302, 12297829382473034411u),
1003
    MakeInt128(-1317624576693539402, 15811494920322472814u),
1004
    MakeInt128(-1152921504606846976, 0u),
1005
    MakeInt128(-1024819115206086201, 2049638230412172402u),
1006
    MakeInt128(-922337203685477581, 3689348814741910324u),
1007
    MakeInt128(-838488366986797801, 5030930201920786805u),
1008
    MakeInt128(-768614336404564651, 6148914691236517206u),
1009
    MakeInt128(-709490156681136601, 7094901566811366007u),
1010
    MakeInt128(-658812288346769701, 7905747460161236407u),
1011
    MakeInt128(-614891469123651721, 8608480567731124088u),
1012
    MakeInt128(-576460752303423488, 0u),
1013
    MakeInt128(-542551296285575048, 8680820740569200761u),
1014
    MakeInt128(-512409557603043101, 10248191152060862009u),
1015
    MakeInt128(-485440633518672411, 970881267037344822u),
1016
    MakeInt128(-461168601842738791, 11068046444225730970u),
1017
    MakeInt128(-439208192231179801, 11419412998010674810u),
1018
    MakeInt128(-419244183493398901, 11738837137815169211u),
1019
    MakeInt128(-401016175515425036, 16040647020617001406u),
1020
    MakeInt128(-384307168202282326, 12297829382473034411u),
1021
    MakeInt128(-368934881474191033, 12543785970122495099u),
1022
    MakeInt128(-354745078340568301, 12770822820260458812u),
1023
    MakeInt128(-341606371735362067, 683212743470724134u),
1024
    MakeInt128(-329406144173384851, 13176245766935394012u),
1025
    MakeInt128(-318047311615681925, 10813608594933185431u),
1026
    MakeInt128(-307445734561825861, 13527612320720337852u),
1027
    MakeInt128(-297528130221121801, 13686293990171602812u),
1028
    MakeInt128(-288230376151711744, 0u),
1029
    MakeInt128(-279496122328932601, 13974806116446630013u),
1030
    MakeInt128(-271275648142787524, 4340410370284600381u),
1031
    MakeInt128(-263524915338707881, 14230345428290225533u),
1032
    MakeInt128(-256204778801521551, 14347467612885206813u),
1033
};
1034
1035
template <typename IntType>
1036
ABSL_CONST_INIT const IntType LookupTables<IntType>::kVmaxOverBase[] =
1037
    X_OVER_BASE_INITIALIZER(std::numeric_limits<IntType>::max());
1038
1039
template <typename IntType>
1040
ABSL_CONST_INIT const IntType LookupTables<IntType>::kVminOverBase[] =
1041
    X_OVER_BASE_INITIALIZER(std::numeric_limits<IntType>::min());
1042
1043
#undef X_OVER_BASE_INITIALIZER
1044
1045
template <typename IntType>
1046
inline bool safe_parse_positive_int(absl::string_view text, int base,
1047
754k
                                    IntType* absl_nonnull value_p) {
1048
754k
  IntType value = 0;
1049
754k
  const IntType vmax = std::numeric_limits<IntType>::max();
1050
754k
  assert(vmax > 0);
1051
754k
  assert(base >= 0);
1052
754k
  const IntType base_inttype = static_cast<IntType>(base);
1053
754k
  assert(vmax >= base_inttype);
1054
754k
  const IntType vmax_over_base = LookupTables<IntType>::kVmaxOverBase[base];
1055
754k
  assert(base < 2 ||
1056
754k
         std::numeric_limits<IntType>::max() / base_inttype == vmax_over_base);
1057
754k
  const char* start = text.data();
1058
754k
  const char* end = start + text.size();
1059
  // loop over digits
1060
6.18M
  for (; start < end; ++start) {
1061
5.43M
    unsigned char c = static_cast<unsigned char>(start[0]);
1062
5.43M
    IntType digit = static_cast<IntType>(kAsciiToInt[c]);
1063
5.43M
    if (digit >= base_inttype) {
1064
207
      *value_p = value;
1065
207
      return false;
1066
207
    }
1067
5.43M
    if (value > vmax_over_base) {
1068
5.78k
      *value_p = vmax;
1069
5.78k
      return false;
1070
5.78k
    }
1071
5.42M
    value *= base_inttype;
1072
5.42M
    if (value > vmax - digit) {
1073
1.64k
      *value_p = vmax;
1074
1.64k
      return false;
1075
1.64k
    }
1076
5.42M
    value += digit;
1077
5.42M
  }
1078
747k
  *value_p = value;
1079
747k
  return true;
1080
754k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<signed char>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, signed char*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<short>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, short*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<int>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, int*)
numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<long>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, long*)
Line
Count
Source
1047
728k
                                    IntType* absl_nonnull value_p) {
1048
728k
  IntType value = 0;
1049
728k
  const IntType vmax = std::numeric_limits<IntType>::max();
1050
728k
  assert(vmax > 0);
1051
728k
  assert(base >= 0);
1052
728k
  const IntType base_inttype = static_cast<IntType>(base);
1053
728k
  assert(vmax >= base_inttype);
1054
728k
  const IntType vmax_over_base = LookupTables<IntType>::kVmaxOverBase[base];
1055
728k
  assert(base < 2 ||
1056
728k
         std::numeric_limits<IntType>::max() / base_inttype == vmax_over_base);
1057
728k
  const char* start = text.data();
1058
728k
  const char* end = start + text.size();
1059
  // loop over digits
1060
5.95M
  for (; start < end; ++start) {
1061
5.22M
    unsigned char c = static_cast<unsigned char>(start[0]);
1062
5.22M
    IntType digit = static_cast<IntType>(kAsciiToInt[c]);
1063
5.22M
    if (digit >= base_inttype) {
1064
92
      *value_p = value;
1065
92
      return false;
1066
92
    }
1067
5.22M
    if (value > vmax_over_base) {
1068
2.37k
      *value_p = vmax;
1069
2.37k
      return false;
1070
2.37k
    }
1071
5.22M
    value *= base_inttype;
1072
5.22M
    if (value > vmax - digit) {
1073
724
      *value_p = vmax;
1074
724
      return false;
1075
724
    }
1076
5.22M
    value += digit;
1077
5.22M
  }
1078
725k
  *value_p = value;
1079
725k
  return true;
1080
728k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<absl::lts_20260107::int128>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, absl::lts_20260107::int128*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<unsigned char>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, unsigned char*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<unsigned short>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, unsigned short*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<unsigned int>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, unsigned int*)
numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<unsigned long>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, unsigned long*)
Line
Count
Source
1047
25.7k
                                    IntType* absl_nonnull value_p) {
1048
25.7k
  IntType value = 0;
1049
25.7k
  const IntType vmax = std::numeric_limits<IntType>::max();
1050
25.7k
  assert(vmax > 0);
1051
25.7k
  assert(base >= 0);
1052
25.7k
  const IntType base_inttype = static_cast<IntType>(base);
1053
25.7k
  assert(vmax >= base_inttype);
1054
25.7k
  const IntType vmax_over_base = LookupTables<IntType>::kVmaxOverBase[base];
1055
25.7k
  assert(base < 2 ||
1056
25.7k
         std::numeric_limits<IntType>::max() / base_inttype == vmax_over_base);
1057
25.7k
  const char* start = text.data();
1058
25.7k
  const char* end = start + text.size();
1059
  // loop over digits
1060
230k
  for (; start < end; ++start) {
1061
208k
    unsigned char c = static_cast<unsigned char>(start[0]);
1062
208k
    IntType digit = static_cast<IntType>(kAsciiToInt[c]);
1063
208k
    if (digit >= base_inttype) {
1064
115
      *value_p = value;
1065
115
      return false;
1066
115
    }
1067
208k
    if (value > vmax_over_base) {
1068
3.40k
      *value_p = vmax;
1069
3.40k
      return false;
1070
3.40k
    }
1071
205k
    value *= base_inttype;
1072
205k
    if (value > vmax - digit) {
1073
921
      *value_p = vmax;
1074
921
      return false;
1075
921
    }
1076
204k
    value += digit;
1077
204k
  }
1078
21.2k
  *value_p = value;
1079
21.2k
  return true;
1080
25.7k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_positive_int<absl::lts_20260107::uint128>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, absl::lts_20260107::uint128*)
1081
1082
template <typename IntType>
1083
inline bool safe_parse_negative_int(absl::string_view text, int base,
1084
19.1k
                                    IntType* absl_nonnull value_p) {
1085
19.1k
  IntType value = 0;
1086
19.1k
  const IntType vmin = std::numeric_limits<IntType>::min();
1087
19.1k
  assert(vmin < 0);
1088
19.1k
  assert(vmin <= 0 - base);
1089
19.1k
  IntType vmin_over_base = LookupTables<IntType>::kVminOverBase[base];
1090
19.1k
  assert(base < 2 ||
1091
19.1k
         std::numeric_limits<IntType>::min() / base == vmin_over_base);
1092
  // 2003 c++ standard [expr.mul]
1093
  // "... the sign of the remainder is implementation-defined."
1094
  // Although (vmin/base)*base + vmin%base is always vmin.
1095
  // 2011 c++ standard tightens the spec but we cannot rely on it.
1096
  // TODO(junyer): Handle this in the lookup table generation.
1097
19.1k
  if (vmin % base > 0) {
1098
0
    vmin_over_base += 1;
1099
0
  }
1100
19.1k
  const char* start = text.data();
1101
19.1k
  const char* end = start + text.size();
1102
  // loop over digits
1103
228k
  for (; start < end; ++start) {
1104
211k
    unsigned char c = static_cast<unsigned char>(start[0]);
1105
211k
    int digit = kAsciiToInt[c];
1106
211k
    if (digit >= base) {
1107
41
      *value_p = value;
1108
41
      return false;
1109
41
    }
1110
211k
    if (value < vmin_over_base) {
1111
1.54k
      *value_p = vmin;
1112
1.54k
      return false;
1113
1.54k
    }
1114
210k
    value *= base;
1115
210k
    if (value < vmin + digit) {
1116
815
      *value_p = vmin;
1117
815
      return false;
1118
815
    }
1119
209k
    value -= digit;
1120
209k
  }
1121
16.7k
  *value_p = value;
1122
16.7k
  return true;
1123
19.1k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_negative_int<signed char>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, signed char*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_negative_int<short>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, short*)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_negative_int<int>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, int*)
numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_negative_int<long>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, long*)
Line
Count
Source
1084
19.1k
                                    IntType* absl_nonnull value_p) {
1085
19.1k
  IntType value = 0;
1086
19.1k
  const IntType vmin = std::numeric_limits<IntType>::min();
1087
19.1k
  assert(vmin < 0);
1088
19.1k
  assert(vmin <= 0 - base);
1089
19.1k
  IntType vmin_over_base = LookupTables<IntType>::kVminOverBase[base];
1090
19.1k
  assert(base < 2 ||
1091
19.1k
         std::numeric_limits<IntType>::min() / base == vmin_over_base);
1092
  // 2003 c++ standard [expr.mul]
1093
  // "... the sign of the remainder is implementation-defined."
1094
  // Although (vmin/base)*base + vmin%base is always vmin.
1095
  // 2011 c++ standard tightens the spec but we cannot rely on it.
1096
  // TODO(junyer): Handle this in the lookup table generation.
1097
19.1k
  if (vmin % base > 0) {
1098
0
    vmin_over_base += 1;
1099
0
  }
1100
19.1k
  const char* start = text.data();
1101
19.1k
  const char* end = start + text.size();
1102
  // loop over digits
1103
228k
  for (; start < end; ++start) {
1104
211k
    unsigned char c = static_cast<unsigned char>(start[0]);
1105
211k
    int digit = kAsciiToInt[c];
1106
211k
    if (digit >= base) {
1107
41
      *value_p = value;
1108
41
      return false;
1109
41
    }
1110
211k
    if (value < vmin_over_base) {
1111
1.54k
      *value_p = vmin;
1112
1.54k
      return false;
1113
1.54k
    }
1114
210k
    value *= base;
1115
210k
    if (value < vmin + digit) {
1116
815
      *value_p = vmin;
1117
815
      return false;
1118
815
    }
1119
209k
    value -= digit;
1120
209k
  }
1121
16.7k
  *value_p = value;
1122
16.7k
  return true;
1123
19.1k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_parse_negative_int<absl::lts_20260107::int128>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int, absl::lts_20260107::int128*)
1124
1125
// Input format based on POSIX.1-2008 strtol
1126
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html
1127
template <typename IntType>
1128
inline bool safe_int_internal(absl::string_view text,
1129
748k
                              IntType* absl_nonnull value_p, int base) {
1130
748k
  *value_p = 0;
1131
748k
  bool negative;
1132
748k
  if (!safe_parse_sign_and_base(&text, &base, &negative)) {
1133
115
    return false;
1134
115
  }
1135
748k
  if (!negative) {
1136
728k
    return safe_parse_positive_int(text, base, value_p);
1137
728k
  } else {
1138
19.1k
    return safe_parse_negative_int(text, base, value_p);
1139
19.1k
  }
1140
748k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_int_internal<signed char>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, signed char*, int)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_int_internal<short>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, short*, int)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_int_internal<int>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, int*, int)
numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_int_internal<long>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, long*, int)
Line
Count
Source
1129
748k
                              IntType* absl_nonnull value_p, int base) {
1130
748k
  *value_p = 0;
1131
748k
  bool negative;
1132
748k
  if (!safe_parse_sign_and_base(&text, &base, &negative)) {
1133
115
    return false;
1134
115
  }
1135
748k
  if (!negative) {
1136
728k
    return safe_parse_positive_int(text, base, value_p);
1137
728k
  } else {
1138
19.1k
    return safe_parse_negative_int(text, base, value_p);
1139
19.1k
  }
1140
748k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_int_internal<absl::lts_20260107::int128>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, absl::lts_20260107::int128*, int)
1141
1142
template <typename IntType>
1143
inline bool safe_uint_internal(absl::string_view text,
1144
25.8k
                               IntType* absl_nonnull value_p, int base) {
1145
25.8k
  *value_p = 0;
1146
25.8k
  bool negative;
1147
25.8k
  if (!safe_parse_sign_and_base(&text, &base, &negative) || negative) {
1148
149
    return false;
1149
149
  }
1150
25.7k
  return safe_parse_positive_int(text, base, value_p);
1151
25.8k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_uint_internal<unsigned char>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned char*, int)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_uint_internal<unsigned short>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned short*, int)
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_uint_internal<unsigned int>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned int*, int)
numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_uint_internal<unsigned long>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned long*, int)
Line
Count
Source
1144
25.8k
                               IntType* absl_nonnull value_p, int base) {
1145
25.8k
  *value_p = 0;
1146
25.8k
  bool negative;
1147
25.8k
  if (!safe_parse_sign_and_base(&text, &base, &negative) || negative) {
1148
149
    return false;
1149
149
  }
1150
25.7k
  return safe_parse_positive_int(text, base, value_p);
1151
25.8k
}
Unexecuted instantiation: numbers.cc:bool absl::lts_20260107::(anonymous namespace)::safe_uint_internal<absl::lts_20260107::uint128>(std::__1::basic_string_view<char, std::__1::char_traits<char> >, absl::lts_20260107::uint128*, int)
1152
}  // anonymous namespace
1153
1154
namespace numbers_internal {
1155
1156
// Digit conversion.
1157
ABSL_CONST_INIT ABSL_DLL const char kHexChar[] =
1158
    "0123456789abcdef";
1159
1160
ABSL_CONST_INIT ABSL_DLL const char kHexTable[513] =
1161
    "000102030405060708090a0b0c0d0e0f"
1162
    "101112131415161718191a1b1c1d1e1f"
1163
    "202122232425262728292a2b2c2d2e2f"
1164
    "303132333435363738393a3b3c3d3e3f"
1165
    "404142434445464748494a4b4c4d4e4f"
1166
    "505152535455565758595a5b5c5d5e5f"
1167
    "606162636465666768696a6b6c6d6e6f"
1168
    "707172737475767778797a7b7c7d7e7f"
1169
    "808182838485868788898a8b8c8d8e8f"
1170
    "909192939495969798999a9b9c9d9e9f"
1171
    "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"
1172
    "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf"
1173
    "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf"
1174
    "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
1175
    "e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
1176
    "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
1177
1178
bool safe_strto8_base(absl::string_view text, int8_t* absl_nonnull value,
1179
0
                      int base) {
1180
0
  return safe_int_internal<int8_t>(text, value, base);
1181
0
}
1182
1183
bool safe_strto16_base(absl::string_view text, int16_t* absl_nonnull value,
1184
0
                       int base) {
1185
0
  return safe_int_internal<int16_t>(text, value, base);
1186
0
}
1187
1188
bool safe_strto32_base(absl::string_view text, int32_t* absl_nonnull value,
1189
0
                       int base) {
1190
0
  return safe_int_internal<int32_t>(text, value, base);
1191
0
}
1192
1193
bool safe_strto64_base(absl::string_view text, int64_t* absl_nonnull value,
1194
748k
                       int base) {
1195
748k
  return safe_int_internal<int64_t>(text, value, base);
1196
748k
}
1197
1198
bool safe_strto128_base(absl::string_view text, int128* absl_nonnull value,
1199
0
                        int base) {
1200
0
  return safe_int_internal<absl::int128>(text, value, base);
1201
0
}
1202
1203
bool safe_strtou8_base(absl::string_view text, uint8_t* absl_nonnull value,
1204
0
                       int base) {
1205
0
  return safe_uint_internal<uint8_t>(text, value, base);
1206
0
}
1207
1208
bool safe_strtou16_base(absl::string_view text, uint16_t* absl_nonnull value,
1209
0
                        int base) {
1210
0
  return safe_uint_internal<uint16_t>(text, value, base);
1211
0
}
1212
1213
bool safe_strtou32_base(absl::string_view text, uint32_t* absl_nonnull value,
1214
0
                        int base) {
1215
0
  return safe_uint_internal<uint32_t>(text, value, base);
1216
0
}
1217
1218
bool safe_strtou64_base(absl::string_view text, uint64_t* absl_nonnull value,
1219
25.8k
                        int base) {
1220
25.8k
  return safe_uint_internal<uint64_t>(text, value, base);
1221
25.8k
}
1222
1223
bool safe_strtou128_base(absl::string_view text, uint128* absl_nonnull value,
1224
0
                         int base) {
1225
0
  return safe_uint_internal<absl::uint128>(text, value, base);
1226
0
}
1227
1228
}  // namespace numbers_internal
1229
ABSL_NAMESPACE_END
1230
}  // namespace absl