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

Method max

Lib/_pydecimal.py:2778–2818  ·  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

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

Callers 15

test_none_argsMethod · 0.95
maxMethod · 0.45
test_subclassingMethod · 0.45
test_named_parametersMethod · 0.45
selectFunction · 0.45
strftime_asciiFunction · 0.45
range_from_objectFunction · 0.45
read_chunkMethod · 0.45
alignmentFunction · 0.45
encode_code_page_errorsFunction · 0.45
decode_code_page_errorsFunction · 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