Lines Matching refs:base
81 * being an internal Python int digit, in base BASE).
1703 /* Convert an integer to a base 10 string. Returns a new non-shared
1748 required to express a in base _PyLong_DECIMAL_BASE:
1769 /* convert array of base _PyLong_BASE digits in pin to an array of
1770 base _PyLong_DECIMAL_BASE digits in pout, following Knuth (TAOCP,
1924 /* Convert an int object to a string, using a given conversion base,
1926 If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'
1930 long_format_binary(PyObject *aa, int base, int alternate,
1942 assert(base == 2 || base == 8 || base == 16);
1951 switch (base) {
2020 cdigit = (char)(accum & (base - 1)); \
2030 if (base == 16) \
2032 else if (base == 8) \
2034 else /* (base == 2) */ \
2092 _PyLong_Format(PyObject *obj, int base)
2096 if (base == 10)
2099 err = long_format_binary(obj, base, 1, &str, NULL, NULL, NULL);
2108 int base, int alternate)
2110 if (base == 10)
2114 return long_format_binary(obj, base, alternate, NULL, writer,
2121 int base, int alternate)
2126 if (base == 10)
2130 res = long_format_binary(obj, base, alternate, NULL, NULL,
2142 * Note that when converting a base B string, a char c is a legitimate
2143 * base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B.
2164 /* *str points to the first digit in a string of base `base` digits. base
2175 long_from_binary_base(const char **str, int base, PyLongObject **res)
2188 assert(base >= 2 && base <= 32 && (base & (base - 1)) == 0);
2189 n = base;
2194 while (_PyLong_DigitValue[Py_CHARMASK(*p)] < base || *p == '_') {
2239 assert(k >= 0 && k < base);
2270 PyLong_FromString(const char *str, char **pend, int base)
2278 if ((base != 0 && base < 2) || base > 36) {
2293 if (base == 0) {
2295 base = 10;
2298 base = 16;
2301 base = 8;
2304 base = 2;
2310 base = 10;
2314 ((base == 16 && (str[1] == 'x' || str[1] == 'X')) ||
2315 (base == 8 && (str[1] == 'o' || str[1] == 'O')) ||
2316 (base == 2 && (str[1] == 'b' || str[1] == 'B')))) {
2329 if ((base & (base - 1)) == 0) {
2331 int res = long_from_binary_base(&str, base, &z);
2340 Python's representation base is binary. Other bases (including decimal!) use
2343 First some math: the largest integer that can be expressed in N base-B digits
2344 is B**N-1. Consequently, if we have an N-digit input in base B, the worst-
2348 BASE**n >= B**N [taking logs to base BASE]
2351 The static array log_base_BASE[base] == log(base)/log(BASE) so we can compute
2355 The input string is actually treated as being in base base**i (i.e., i digits
2358 convwidth_base[base] = the largest integer i such that base**i <= BASE
2359 convmultmax_base[base] = base ** convwidth_base[base]
2363 base we're really using.
2365 Viewing the input as a sequence <c0, c1, ..., c_n-1> of digits in base
2366 convmultmax_base[base], the result is "simply"
2370 where B = convmultmax_base[base].
2377 where `N` is the number of input digits in base `B`. This is computed via
2379 size_z = (Py_ssize_t)((scan - str) * log_base_BASE[base]) + 1;
2437 if (log_base_BASE[base] == 0.0) {
2438 twodigits convmax = base;
2441 log_base_BASE[base] = (log((double)base) /
2444 twodigits next = convmax * base;
2451 convmultmax_base[base] = convmax;
2453 convwidth_base[base] = i;
2460 while (_PyLong_DigitValue[Py_CHARMASK(*scan)] < base || *scan == '_') {
2494 * integer with this base and length. Note that there's no
2498 double fsize_z = (double)digits * log_base_BASE[base] + 1.0;
2516 * digit in base `convmultmax`.
2518 convwidth = convwidth_base[base];
2519 convmultmax = convmultmax_base[base];
2534 c = (twodigits)(c * base +
2544 convmult = base;
2546 convmult *= base;
2589 /* reset the base to 0, else the exception message
2591 base = 0;
2595 /* there might still be other problems, therefore base
2631 "invalid literal for int() with base %d: %.200R",
2632 base, strobj);
2643 _PyLong_FromBytes(const char *s, Py_ssize_t len, int base)
2648 result = PyLong_FromString(s, &end, base);
2655 "invalid literal for int() with base %d: %.200R",
2656 base, strobj);
2663 PyLong_FromUnicodeObject(PyObject *u, int base)
2678 result = PyLong_FromString(buffer, &end, base);
2686 "invalid literal for int() with base %d: %.200R",
2687 base, u);
3415 * that still holds a 0. Where the base
4349 "base is not invertible for the given modulus");
4449 replace the base with a modular inverse */
4469 /* Reduce base by modulus in some cases:
4470 1. If base < 0. Forcing the base non-negative makes things easier.
4471 2. If base is obviously larger than the modulus. The "small
4472 exponent" case later can multiply directly by base repeatedly,
4473 while the "large exponent" case multiplies directly by base 31
4475 base % modulus instead.
5350 base as obase: object(c_default="NULL") = 10
5357 Py_ssize_t base;
5369 /* default base and limit, forward to standard implementation */
5373 base = PyNumber_AsSsize_t(obase, NULL);
5374 if (base == -1 && PyErr_Occurred())
5376 if ((base != 0 && base < 2) || base > 36) {
5378 "int() base must be >= 2 and <= 36, or 0");
5383 return PyLong_FromUnicodeObject(x, (int)base);
5390 return _PyLong_FromBytes(string, Py_SIZE(x), (int)base);
5394 "int() can't convert non-string with explicit base");
6007 int(x, base=10) -> integer\n\
6013 If x is not a number or if base is given, then x must be a string,\n\
6015 given base. The literal can be preceded by '+' or '-' and be surrounded\n\
6016 by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n\
6017 Base 0 means to interpret the base from the string as an integer literal.\n\
6018 >>> int('0b100', base=0)\n\