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

Method compare

Lib/_pydecimal.py:4168–4202  ·  view source on GitHub ↗

Compares values numerically. If the signs of the operands differ, a value representing each operand ('-1' if the operand is less than zero, '0' if the operand is zero or negative zero, or '1' if the operand is greater than zero) is used in place of that operand for t

(self, a, b)

Source from the content-addressed store, hash-verified

4166 return a.canonical()
4167
4168 def compare(self, a, b):
4169 """Compares values numerically.
4170
4171 If the signs of the operands differ, a value representing each operand
4172 ('-1' if the operand is less than zero, '0' if the operand is zero or
4173 negative zero, or '1' if the operand is greater than zero) is used in
4174 place of that operand for the comparison instead of the actual
4175 operand.
4176
4177 The comparison is then effected by subtracting the second operand from
4178 the first and then returning a value according to the result of the
4179 subtraction: '-1' if the result is less than zero, '0' if the result is
4180 zero or negative zero, or '1' if the result is greater than zero.
4181
4182 >>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
4183 Decimal('-1')
4184 >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
4185 Decimal('0')
4186 >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
4187 Decimal('0')
4188 >>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
4189 Decimal('1')
4190 >>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
4191 Decimal('1')
4192 >>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
4193 Decimal('-1')
4194 >>> ExtendedContext.compare(1, 2)
4195 Decimal('-1')
4196 >>> ExtendedContext.compare(Decimal(1), 2)
4197 Decimal('-1')
4198 >>> ExtendedContext.compare(1, Decimal(2))
4199 Decimal('-1')
4200 """
4201 a = _convert_other(a, raiseit=True)
4202 return a.compare(b, context=self)
4203
4204 def compare_signal(self, a, b):
4205 """Compares the values of the two operands numerically.

Callers 1

test_compareMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
compareMethod · 0.45

Tested by 1

test_compareMethod · 0.76