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)
| 2824 | return ans |
| 2825 | |
| 2826 | def max(self, other, context=None): |
| 2827 | """Returns the larger value. |
| 2828 | |
| 2829 | Like max(self, other) except if one is not a number, returns |
| 2830 | NaN (and signals if one is sNaN). Also rounds. |
| 2831 | """ |
| 2832 | other = _convert_other(other, raiseit=True) |
| 2833 | |
| 2834 | if context is None: |
| 2835 | context = getcontext() |
| 2836 | |
| 2837 | if self._is_special or other._is_special: |
| 2838 | # If one operand is a quiet NaN and the other is number, then the |
| 2839 | # number is always returned |
| 2840 | sn = self._isnan() |
| 2841 | on = other._isnan() |
| 2842 | if sn or on: |
| 2843 | if on == 1 and sn == 0: |
| 2844 | return self._fix(context) |
| 2845 | if sn == 1 and on == 0: |
| 2846 | return other._fix(context) |
| 2847 | return self._check_nans(other, context) |
| 2848 | |
| 2849 | c = self._cmp(other) |
| 2850 | if c == 0: |
| 2851 | # If both operands are finite and equal in numerical value |
| 2852 | # then an ordering is applied: |
| 2853 | # |
| 2854 | # If the signs differ then max returns the operand with the |
| 2855 | # positive sign and min returns the operand with the negative sign |
| 2856 | # |
| 2857 | # If the signs are the same then the exponent is used to select |
| 2858 | # the result. This is exactly the ordering used in compare_total. |
| 2859 | c = self.compare_total(other) |
| 2860 | |
| 2861 | if c == -1: |
| 2862 | ans = other |
| 2863 | else: |
| 2864 | ans = self |
| 2865 | |
| 2866 | return ans._fix(context) |
| 2867 | |
| 2868 | def min(self, other, context=None): |
| 2869 | """Returns the smaller value. |
no test coverage detected