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

Method to_integral_exact

Lib/_pydecimal.py:2634–2661  ·  view source on GitHub ↗

Rounds to a nearby integer. If no rounding mode is specified, take the rounding mode from the context. This method raises the Rounded and Inexact flags when appropriate. See also: to_integral_value, which does exactly the same as this method except that it

(self, rounding=None, context=None)

Source from the content-addressed store, hash-verified

2632 return ans
2633
2634 def to_integral_exact(self, rounding=None, context=None):
2635 """Rounds to a nearby integer.
2636
2637 If no rounding mode is specified, take the rounding mode from
2638 the context. This method raises the Rounded and Inexact flags
2639 when appropriate.
2640
2641 See also: to_integral_value, which does exactly the same as
2642 this method except that it doesn't raise Inexact or Rounded.
2643 """
2644 if self._is_special:
2645 ans = self._check_nans(context=context)
2646 if ans:
2647 return ans
2648 return Decimal(self)
2649 if self._exp >= 0:
2650 return Decimal(self)
2651 if not self:
2652 return _dec_from_triple(self._sign, '0', 0)
2653 if context is None:
2654 context = getcontext()
2655 if rounding is None:
2656 rounding = context.rounding
2657 ans = self._rescale(0, rounding)
2658 if ans != self:
2659 context._raise_error(Inexact)
2660 context._raise_error(Rounded)
2661 return ans
2662
2663 def to_integral_value(self, rounding=None, context=None):
2664 """Rounds to the nearest integer, without raising inexact, rounded."""

Callers 5

test_c_integralMethod · 0.95
to_integral_exactMethod · 0.45
test_none_argsMethod · 0.45
test_named_parametersMethod · 0.45
test_implicit_contextMethod · 0.45

Calls 6

_check_nansMethod · 0.95
_rescaleMethod · 0.95
DecimalClass · 0.85
_dec_from_tripleFunction · 0.85
getcontextFunction · 0.85
_raise_errorMethod · 0.80

Tested by 4

test_c_integralMethod · 0.76
test_none_argsMethod · 0.36
test_named_parametersMethod · 0.36
test_implicit_contextMethod · 0.36