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

Method compare

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

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