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

Method copy_sign

Lib/_pydecimal.py:4315–4337  ·  view source on GitHub ↗

Copies the second operand's sign to the first one. In detail, it returns a copy of the first operand with the sign equal to the sign of the second operand. >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33')) Decimal('1.50') >>> ExtendedContext.c

(self, a, b)

Source from the content-addressed store, hash-verified

4313 return a.copy_negate()
4314
4315 def copy_sign(self, a, b):
4316 """Copies the second operand's sign to the first one.
4317
4318 In detail, it returns a copy of the first operand with the sign
4319 equal to the sign of the second operand.
4320
4321 >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
4322 Decimal('1.50')
4323 >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
4324 Decimal('1.50')
4325 >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
4326 Decimal('-1.50')
4327 >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
4328 Decimal('-1.50')
4329 >>> ExtendedContext.copy_sign(1, -2)
4330 Decimal('-1')
4331 >>> ExtendedContext.copy_sign(Decimal(1), -2)
4332 Decimal('-1')
4333 >>> ExtendedContext.copy_sign(1, Decimal(-2))
4334 Decimal('-1')
4335 """
4336 a = _convert_other(a, raiseit=True)
4337 return a.copy_sign(b)
4338
4339 def divide(self, a, b):
4340 """Decimal division in a specified context.

Callers 2

test_copy_signMethod · 0.95
test_copyMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
copy_signMethod · 0.45

Tested by 2

test_copy_signMethod · 0.76
test_copyMethod · 0.76