MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __add__

Method __add__

tools/python-3.11.9-amd64/Lib/_pydecimal.py:1167–1251  ·  view source on GitHub ↗

Returns self + other. -INF + INF (or the reverse) cause InvalidOperation errors.

(self, other, context=None)

Source from the content-addressed store, hash-verified

1165 return ans
1166
1167 def __add__(self, other, context=None):
1168 """Returns self + other.
1169
1170 -INF + INF (or the reverse) cause InvalidOperation errors.
1171 """
1172 other = _convert_other(other)
1173 if other is NotImplemented:
1174 return other
1175
1176 if context is None:
1177 context = getcontext()
1178
1179 if self._is_special or other._is_special:
1180 ans = self._check_nans(other, context)
1181 if ans:
1182 return ans
1183
1184 if self._isinfinity():
1185 # If both INF, same sign => same as both, opposite => error.
1186 if self._sign != other._sign and other._isinfinity():
1187 return context._raise_error(InvalidOperation, '-INF + INF')
1188 return Decimal(self)
1189 if other._isinfinity():
1190 return Decimal(other) # Can't both be infinity here
1191
1192 exp = min(self._exp, other._exp)
1193 negativezero = 0
1194 if context.rounding == ROUND_FLOOR and self._sign != other._sign:
1195 # If the answer is 0, the sign should be negative, in this case.
1196 negativezero = 1
1197
1198 if not self and not other:
1199 sign = min(self._sign, other._sign)
1200 if negativezero:
1201 sign = 1
1202 ans = _dec_from_triple(sign, '0', exp)
1203 ans = ans._fix(context)
1204 return ans
1205 if not self:
1206 exp = max(exp, other._exp - context.prec-1)
1207 ans = other._rescale(exp, context.rounding)
1208 ans = ans._fix(context)
1209 return ans
1210 if not other:
1211 exp = max(exp, self._exp - context.prec-1)
1212 ans = self._rescale(exp, context.rounding)
1213 ans = ans._fix(context)
1214 return ans
1215
1216 op1 = _WorkRep(self)
1217 op2 = _WorkRep(other)
1218 op1, op2 = _normalize(op1, op2, context.prec)
1219
1220 result = _WorkRep()
1221 if op1.sign != op2.sign:
1222 # Equal and opposite
1223 if op1.int == op2.int:
1224 ans = _dec_from_triple(negativezero, '0', exp)

Callers 4

__sub__Method · 0.95
next_plusMethod · 0.95
fmaMethod · 0.45
addMethod · 0.45

Calls 13

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
_fixMethod · 0.95
_rescaleMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85
DecimalClass · 0.85
minFunction · 0.85
_dec_from_tripleFunction · 0.85
maxFunction · 0.85
_WorkRepClass · 0.85
_normalizeFunction · 0.85

Tested by

no test coverage detected