1 #ifndef Py_CPYTHON_LONGOBJECT_H
2 #  error "this header file must not be included directly"
3 #endif
4 
5 PyAPI_FUNC(int) _PyLong_AsInt(PyObject *);
6 
7 PyAPI_FUNC(int) _PyLong_UnsignedShort_Converter(PyObject *, void *);
8 PyAPI_FUNC(int) _PyLong_UnsignedInt_Converter(PyObject *, void *);
9 PyAPI_FUNC(int) _PyLong_UnsignedLong_Converter(PyObject *, void *);
10 PyAPI_FUNC(int) _PyLong_UnsignedLongLong_Converter(PyObject *, void *);
11 PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);
12 
13 /* _PyLong_Frexp returns a double x and an exponent e such that the
14    true value is approximately equal to x * 2**e.  e is >= 0.  x is
15    0.0 if and only if the input is 0 (in which case, e and x are both
16    zeroes); otherwise, 0.5 <= abs(x) < 1.0.  On overflow, which is
17    possible if the number of bits doesn't fit into a Py_ssize_t, sets
18    OverflowError and returns -1.0 for x, 0 for e. */
19 PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);
20 
21 PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base);
22 PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int);
23 
24 /* _PyLong_Sign.  Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
25    v must not be NULL, and must be a normalized long.
26    There are no error cases.
27 */
28 PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
29 
30 /* _PyLong_NumBits.  Return the number of bits needed to represent the
31    absolute value of a long.  For example, this returns 1 for 1 and -1, 2
32    for 2 and -2, and 2 for 3 and -3.  It returns 0 for 0.
33    v must not be NULL, and must be a normalized long.
34    (size_t)-1 is returned and OverflowError set if the true result doesn't
35    fit in a size_t.
36 */
37 PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
38 
39 /* _PyLong_DivmodNear.  Given integers a and b, compute the nearest
40    integer q to the exact quotient a / b, rounding to the nearest even integer
41    in the case of a tie.  Return (q, r), where r = a - q*b.  The remainder r
42    will satisfy abs(r) <= abs(b)/2, with equality possible only if q is
43    even.
44 */
45 PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *);
46 
47 /* _PyLong_FromByteArray:  View the n unsigned bytes as a binary integer in
48    base 256, and return a Python int with the same numeric value.
49    If n is 0, the integer is 0.  Else:
50    If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB;
51    else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the
52    LSB.
53    If is_signed is 0/false, view the bytes as a non-negative integer.
54    If is_signed is 1/true, view the bytes as a 2's-complement integer,
55    non-negative if bit 0x80 of the MSB is clear, negative if set.
56    Error returns:
57    + Return NULL with the appropriate exception set if there's not
58      enough memory to create the Python int.
59 */
60 PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
61     const unsigned char* bytes, size_t n,
62     int little_endian, int is_signed);
63 
64 /* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long
65    v to a base-256 integer, stored in array bytes.  Normally return 0,
66    return -1 on error.
67    If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at
68    bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and
69    the LSB at bytes[n-1].
70    If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes
71    are filled and there's nothing special about bit 0x80 of the MSB.
72    If is_signed is 1/true, bytes is filled with the 2's-complement
73    representation of v's value.  Bit 0x80 of the MSB is the sign bit.
74    Error returns (-1):
75    + is_signed is 0 and v < 0.  TypeError is set in this case, and bytes
76      isn't altered.
77    + n isn't big enough to hold the full mathematical value of v.  For
78      example, if is_signed is 0 and there are more digits in the v than
79      fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of
80      being large enough to hold a sign bit.  OverflowError is set in this
81      case, but bytes holds the least-significant n bytes of the true value.
82 */
83 PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
84     unsigned char* bytes, size_t n,
85     int little_endian, int is_signed);
86 
87 /* _PyLong_Format: Convert the long to a string object with given base,
88    appending a base prefix of 0[box] if base is 2, 8 or 16. */
89 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *obj, int base);
90 
91 /* For use by the gcd function in mathmodule.c */
92 PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
93 
94 PyAPI_FUNC(PyObject *) _PyLong_Rshift(PyObject *, size_t);
95 PyAPI_FUNC(PyObject *) _PyLong_Lshift(PyObject *, size_t);
96