x.__hash__() <==> hash(x)
(self)
| 895 | return Decimal(self._cmp(other)) |
| 896 | |
| 897 | def __hash__(self): |
| 898 | """x.__hash__() <==> hash(x)""" |
| 899 | |
| 900 | # In order to make sure that the hash of a Decimal instance |
| 901 | # agrees with the hash of a numerically equal integer, float |
| 902 | # or Fraction, we follow the rules for numeric hashes outlined |
| 903 | # in the documentation. (See library docs, 'Built-in Types'). |
| 904 | if self._is_special: |
| 905 | if self.is_snan(): |
| 906 | raise TypeError('Cannot hash a signaling NaN value.') |
| 907 | elif self.is_nan(): |
| 908 | return object.__hash__(self) |
| 909 | else: |
| 910 | if self._sign: |
| 911 | return -_PyHASH_INF |
| 912 | else: |
| 913 | return _PyHASH_INF |
| 914 | |
| 915 | if self._exp >= 0: |
| 916 | exp_hash = pow(10, self._exp, _PyHASH_MODULUS) |
| 917 | else: |
| 918 | exp_hash = pow(_PyHASH_10INV, -self._exp, _PyHASH_MODULUS) |
| 919 | hash_ = int(self._int) * exp_hash % _PyHASH_MODULUS |
| 920 | ans = hash_ if self >= 0 else -hash_ |
| 921 | return -2 if ans == -1 else ans |
| 922 | |
| 923 | def as_tuple(self): |
| 924 | """Represents the number as a triple tuple. |