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

Method to_integral_exact

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

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