Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

  1. #ifndef Py_LONGINTREPR_H
  2. #define Py_LONGINTREPR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* This is published for the benefit of "friend" marshal.c only. */
  7. /* Parameters of the long integer representation.
  8. These shouldn't have to be changed as C should guarantee that a short
  9. contains at least 16 bits, but it's made changeable anyway.
  10. Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
  11. should be able to hold the intermediate results in 'mul'
  12. (at most (BASE-1)*(2*BASE+1) == MASK*(2*MASK+3)).
  13. Also, x_sub assumes that 'digit' is an unsigned type, and overflow
  14. is handled by taking the result mod 2**N for some N > SHIFT.
  15. And, at some places it is assumed that MASK fits in an int, as well.
  16. long_pow() requires that SHIFT be divisible by 5. */
  17. typedef unsigned short digit;
  18. typedef unsigned int wdigit; /* digit widened to parameter size */
  19. #define BASE_TWODIGITS_TYPE long
  20. typedef unsigned BASE_TWODIGITS_TYPE twodigits;
  21. typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
  22. #define SHIFT 15
  23. #define BASE ((digit)1 << SHIFT)
  24. #define MASK ((int)(BASE - 1))
  25. #if SHIFT % 5 != 0
  26. #error "longobject.c requires that SHIFT be divisible by 5"
  27. #endif
  28. /* Long integer representation.
  29. The absolute value of a number is equal to
  30. SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
  31. Negative numbers are represented with ob_size < 0;
  32. zero is represented by ob_size == 0.
  33. In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
  34. digit) is never zero. Also, in all cases, for all valid i,
  35. 0 <= ob_digit[i] <= MASK.
  36. The allocation function takes care of allocating extra memory
  37. so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.
  38. CAUTION: Generic code manipulating subtypes of PyVarObject has to
  39. aware that longs abuse ob_size's sign bit.
  40. */
  41. struct _longobject {
  42. PyObject_VAR_HEAD
  43. digit ob_digit[1];
  44. };
  45. PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
  46. /* Return a copy of src. */
  47. PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif /* !Py_LONGINTREPR_H */