MCPcopy Index your code
hub / github.com/RustPython/RustPython / compare_total

Method compare_total

Lib/_pydecimal.py:2897–2967  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 7

maxMethod · 0.95
minMethod · 0.95
max_magMethod · 0.95
min_magMethod · 0.95
compare_total_magMethod · 0.45
compare_totalMethod · 0.45

Calls 3

_isnanMethod · 0.95
_convert_otherFunction · 0.85
lenFunction · 0.85

Tested by 1