Compares self to other using the abstract representations. This is not like the standard compare, which use their numerical value. Note that a total ordering is defined for all possible abstract representations.
(self, other, context=None)
| 2898 | return self.compare(other, context=context) |
| 2899 | |
| 2900 | def compare_total(self, other, context=None): |
| 2901 | """Compares self to other using the abstract representations. |
| 2902 | |
| 2903 | This is not like the standard compare, which use their numerical |
| 2904 | value. Note that a total ordering is defined for all possible abstract |
| 2905 | representations. |
| 2906 | """ |
| 2907 | other = _convert_other(other, raiseit=True) |
| 2908 | |
| 2909 | # if one is negative and the other is positive, it's easy |
| 2910 | if self._sign and not other._sign: |
| 2911 | return _NegativeOne |
| 2912 | if not self._sign and other._sign: |
| 2913 | return _One |
| 2914 | sign = self._sign |
| 2915 | |
| 2916 | # let's handle both NaN types |
| 2917 | self_nan = self._isnan() |
| 2918 | other_nan = other._isnan() |
| 2919 | if self_nan or other_nan: |
| 2920 | if self_nan == other_nan: |
| 2921 | # compare payloads as though they're integers |
| 2922 | self_key = len(self._int), self._int |
| 2923 | other_key = len(other._int), other._int |
| 2924 | if self_key < other_key: |
| 2925 | if sign: |
| 2926 | return _One |
| 2927 | else: |
| 2928 | return _NegativeOne |
| 2929 | if self_key > other_key: |
| 2930 | if sign: |
| 2931 | return _NegativeOne |
| 2932 | else: |
| 2933 | return _One |
| 2934 | return _Zero |
| 2935 | |
| 2936 | if sign: |
| 2937 | if self_nan == 1: |
| 2938 | return _NegativeOne |
| 2939 | if other_nan == 1: |
| 2940 | return _One |
| 2941 | if self_nan == 2: |
| 2942 | return _NegativeOne |
| 2943 | if other_nan == 2: |
| 2944 | return _One |
| 2945 | else: |
| 2946 | if self_nan == 1: |
| 2947 | return _One |
| 2948 | if other_nan == 1: |
| 2949 | return _NegativeOne |
| 2950 | if self_nan == 2: |
| 2951 | return _One |
| 2952 | if other_nan == 2: |
| 2953 | return _NegativeOne |
| 2954 | |
| 2955 | if self < other: |
| 2956 | return _NegativeOne |
| 2957 | if self > other: |