MCPcopy Index your code
hub / github.com/python/cpython / max

Method max

Lib/_pydecimal.py:2781–2821  ·  view source on GitHub ↗

Returns the larger value. Like max(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds.

(self, other, context=None)

Source from the content-addressed store, hash-verified

2779 return ans
2780
2781 def max(self, other, context=None):
2782 """Returns the larger value.
2783
2784 Like max(self, other) except if one is not a number, returns
2785 NaN (and signals if one is sNaN). Also rounds.
2786 """
2787 other = _convert_other(other, raiseit=True)
2788
2789 if context is None:
2790 context = getcontext()
2791
2792 if self._is_special or other._is_special:
2793 # If one operand is a quiet NaN and the other is number, then the
2794 # number is always returned
2795 sn = self._isnan()
2796 on = other._isnan()
2797 if sn or on:
2798 if on == 1 and sn == 0:
2799 return self._fix(context)
2800 if sn == 1 and on == 0:
2801 return other._fix(context)
2802 return self._check_nans(other, context)
2803
2804 c = self._cmp(other)
2805 if c == 0:
2806 # If both operands are finite and equal in numerical value
2807 # then an ordering is applied:
2808 #
2809 # If the signs differ then max returns the operand with the
2810 # positive sign and min returns the operand with the negative sign
2811 #
2812 # If the signs are the same then the exponent is used to select
2813 # the result. This is exactly the ordering used in compare_total.
2814 c = self.compare_total(other)
2815
2816 if c == -1:
2817 ans = other
2818 else:
2819 ans = self
2820
2821 return ans._fix(context)
2822
2823 def min(self, other, context=None):
2824 """Returns the smaller value.

Callers 15

test_none_argsMethod · 0.95
maxMethod · 0.45
calculateMenuPositionFunction · 0.45
buildScrollMarkerFunction · 0.45
populateBytecodePanelFunction · 0.45
yFunction · 0.45
XFunction · 0.45
KFunction · 0.45
rtFunction · 0.45
ltFunction · 0.45
ktFunction · 0.45
hFunction · 0.45

Calls 7

_isnanMethod · 0.95
_fixMethod · 0.95
_check_nansMethod · 0.95
_cmpMethod · 0.95
compare_totalMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85

Tested by 4

test_none_argsMethod · 0.76
test_subclassingMethod · 0.36
test_named_parametersMethod · 0.36