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)
| 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. |