»Core Development>Code coverage>Modules/_decimal/tests/bignum.py

# Python code coverage for Modules/_decimal/tests/bignum.py

#countcontent
1n/a#
2n/a# These tests require gmpy and test the limits of the 32-bit build. The
3n/a# limits of the 64-bit build are so large that they cannot be tested
4n/a# on accessible hardware.
5n/a#
6n/a
7n/aimport sys
8n/afrom decimal import *
9n/afrom gmpy import mpz
10n/a
11n/a
12n/a_PyHASH_MODULUS = sys.hash_info.modulus
13n/a# hash values to use for positive and negative infinities, and nans
14n/a_PyHASH_INF = sys.hash_info.inf
15n/a_PyHASH_NAN = sys.hash_info.nan
16n/a
17n/a# _PyHASH_10INV is the inverse of 10 modulo the prime _PyHASH_MODULUS
18n/a_PyHASH_10INV = pow(10, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
19n/a
21n/a sign = 1
22n/a if coeff < 0:
23n/a sign = -1
24n/a coeff = -coeff
25n/a if exp >= 0:
26n/a exp_hash = pow(10, exp, _PyHASH_MODULUS)
27n/a else:
28n/a exp_hash = pow(_PyHASH_10INV, -exp, _PyHASH_MODULUS)
29n/a hash_ = coeff * exp_hash % _PyHASH_MODULUS
30n/a ans = hash_ if sign == 1 else -hash_
31n/a return -2 if ans == -1 else ans
32n/a
33n/a
34n/ax = mpz(10) ** 425000000 - 1
35n/acoeff = int(x)
36n/a
37n/ad = Decimal('9' * 425000000 + 'e-849999999')
38n/a
39n/ah1 = xhash(coeff, -849999999)
40n/ah2 = hash(d)
41n/a
42n/aassert h2 == h1