Python operator.op() Examples
The following are 23
code examples of operator.op().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
operator
, or try the search function
.
Example #1
Source File: fractions.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #2
Source File: fractions.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #3
Source File: fractions.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #4
Source File: fractions.py From canape with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #5
Source File: fractions.py From android_universal with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #6
Source File: fractions.py From unity-python with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #7
Source File: fractions.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #8
Source File: fractions.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #9
Source File: fractions.py From RevitBatchProcessor with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #10
Source File: fractions.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #11
Source File: fractions.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #12
Source File: fractions.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #13
Source File: fractions.py From jawfish with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #14
Source File: fractions.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #15
Source File: fractions.py From datafari with Apache License 2.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #16
Source File: fractions.py From ironpython3 with Apache License 2.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #17
Source File: fractions.py From Imogen with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #18
Source File: fractions.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, numbers.Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #19
Source File: fractions.py From oss-ftp with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #20
Source File: fractions.py From Computable with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #21
Source File: fractions.py From BinderFilter with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #22
Source File: fractions.py From ironpython2 with Apache License 2.0 | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented
Example #23
Source File: fractions.py From meddle with MIT License | 6 votes |
def _richcmp(self, other, op): """Helper for comparison operators, for internal use only. Implement comparison between a Rational instance `self`, and either another Rational instance or a float `other`. If `other` is not a Rational instance or a float, return NotImplemented. `op` should be one of the six standard comparison operators. """ # convert other to a Rational instance where reasonable. if isinstance(other, Rational): return op(self._numerator * other.denominator, self._denominator * other.numerator) # comparisons with complex should raise a TypeError, for consistency # with int<->complex, float<->complex, and complex<->complex comparisons. if isinstance(other, complex): raise TypeError("no ordering relation is defined for complex numbers") if isinstance(other, float): if math.isnan(other) or math.isinf(other): return op(0.0, other) else: return op(self, self.from_float(other)) else: return NotImplemented