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

Method __neg__

Lib/_pydecimal.py:1046–1066  ·  view source on GitHub ↗

Returns a copy with the sign switched. Rounds, if it has reason.

(self, context=None)

Source from the content-addressed store, hash-verified

1044 return self.__str__(eng=True, context=context)
1045
1046 def __neg__(self, context=None):
1047 """Returns a copy with the sign switched.
1048
1049 Rounds, if it has reason.
1050 """
1051 if self._is_special:
1052 ans = self._check_nans(context=context)
1053 if ans:
1054 return ans
1055
1056 if context is None:
1057 context = getcontext()
1058
1059 if not self and context.rounding != ROUND_FLOOR:
1060 # -Decimal('0') is Decimal('0'), not Decimal('-0'), except
1061 # in ROUND_FLOOR rounding mode.
1062 ans = self.copy_abs()
1063 else:
1064 ans = self.copy_negate()
1065
1066 return ans._fix(context)
1067
1068 def __pos__(self, context=None):
1069 """Returns a copy, unless it is a sNaN.

Callers 2

__abs__Method · 0.95
minusMethod · 0.45

Calls 5

_check_nansMethod · 0.95
copy_absMethod · 0.95
copy_negateMethod · 0.95
getcontextFunction · 0.85
_fixMethod · 0.80

Tested by

no test coverage detected