Lines Matching refs:rounding
317 """Invalid context. Unknown rounding, for example.
322 underlying concrete representation or an unknown or unsupported rounding
331 """Number got rounded (not necessarily changed during rounding).
343 """Exponent < Emin before rounding.
347 Emin, before any rounding). The result in all cases is unchanged.
358 by zero), after rounding, would be greater than the largest value that
361 The result depends on the rounding mode:
376 if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
380 if context.rounding == ROUND_CEILING:
385 if context.rounding == ROUND_FLOOR:
431 # Valid rounding modes
445 ['prec', 'Emin', 'Emax', 'capitals', 'clamp', 'rounding', 'flags', 'traps']
1115 if not self and context.rounding != ROUND_FLOOR:
1117 # in ROUND_FLOOR rounding mode.
1137 if not self and context.rounding != ROUND_FLOOR:
1138 # + (-0) = 0, except in ROUND_FLOOR rounding mode.
1194 if context.rounding == ROUND_FLOOR and self._sign != other._sign:
1207 ans = other._rescale(exp, context.rounding)
1212 ans = self._rescale(exp, context.rounding)
1380 # result is not exact; adjust to ensure correct rounding
1408 self._rescale(ideal_exp, context.rounding))
1555 ans = self._rescale(ideal_exponent, context.rounding)
1722 rounding_method = self._pick_rounding_function[context.rounding]
1731 # check whether the rounding pushed the exponent out of range
1763 # for each of the rounding functions below:
1869 decimal places using the rounding mode for the current
1935 Returns self*other+third with no rounding of the intermediate
1938 self and other are multiplied together, with no rounding of
1940 and a single final rounding is performed.
2356 # negate self, without doing any unwanted rounding
2464 # rounding mode; no need to switch to ROUND_HALF_EVEN here
2546 def quantize(self, exp, rounding=None, context=None):
2555 if rounding is None:
2556 rounding = context.rounding
2586 ans = self._rescale(exp._exp, rounding)
2622 def _rescale(self, exp, rounding):
2624 or by truncating digits, using the given rounding mode.
2631 rounding = rounding mode
2644 # exp-1, replace self by 10**(exp-1) before rounding
2649 this_function = self._pick_rounding_function[rounding]
2656 def _round(self, places, rounding):
2658 significant figures, using the given rounding mode.
2670 ans = self._rescale(self.adjusted()+1-places, rounding)
2672 # for example when rounding 99.97 to 3 significant figures.
2676 ans = ans._rescale(ans.adjusted()+1-places, rounding)
2679 def to_integral_exact(self, rounding=None, context=None):
2682 If no rounding mode is specified, take the rounding mode from
2700 if rounding is None:
2701 rounding = context.rounding
2702 ans = self._rescale(0, rounding)
2708 def to_integral_value(self, rounding=None, context=None):
2712 if rounding is None:
2713 rounding = context.rounding
2722 return self._rescale(0, rounding)
2758 # To ensure correct rounding in all cases, we use the
2760 # place (precision p+1 instead of precision p), rounding down.
2820 rounding = context._set_rounding(ROUND_HALF_EVEN)
2822 context.rounding = rounding
3113 # rounding mode, not just with ROUND_HALF_EVEN
3115 rounding = context._set_rounding(ROUND_HALF_EVEN)
3117 context.rounding = rounding
3247 rounding = context._set_rounding(ROUND_HALF_EVEN)
3249 context.rounding = rounding
3308 # answer may need rounding
3328 rounding = context._set_rounding(ROUND_HALF_EVEN)
3330 context.rounding = rounding
3794 # round if necessary, taking rounding mode from the context
3795 rounding = context.rounding
3799 self = self._round(precision+1, rounding)
3801 self = self._rescale(-precision, rounding)
3803 self = self._round(precision, rounding)
3807 self = self._rescale(0, rounding)
3887 prec - precision (for use in rounding, division, square roots..)
3888 rounding - rounding type (how you round)
3902 def __init__(self, prec=None, rounding=None, Emin=None, Emax=None,
3913 self.rounding = rounding if rounding is not None else dc.rounding
3974 elif name == 'rounding':
3978 raise TypeError("%s: invalid rounding mode" % value)
3996 (self.prec, self.rounding, self.Emin, self.Emax,
4002 s.append('Context(prec=%(prec)d, rounding=%(rounding)s, '
4024 nc = Context(self.prec, self.rounding, self.Emin, self.Emax,
4031 nc = Context(self.prec, self.rounding, self.Emin, self.Emax,
4090 """Sets the rounding type.
4092 Sets the rounding type, and returns the current (previous)
4093 rounding type. Often used like:
4098 rounding = context._set_rounding(ROUND_UP)
4100 context._set_rounding(rounding)
4104 rounding = self.rounding
4105 self.rounding = type
4106 return rounding
4126 """Creates a new Decimal instance from a float but rounding using self
4129 >>> context = Context(prec=5, rounding=ROUND_DOWN)
4140 return d._fix(self) # Apply the context rounding
4482 multiplication, using add, all with only one final rounding.
5239 operand. It may be rounded using the current rounding setting (if the
5573 are allowed in this operation. The rounding mode is taken from the
5603 be set. The rounding mode is taken from the context.
5667 # Then adding 10**exp to tmp has the same effect (after rounding)
5960 # rounding down
6089 prec=28, rounding=ROUND_HALF_EVEN,
6104 prec=9, rounding=ROUND_HALF_UP,
6110 prec=9, rounding=ROUND_HALF_EVEN,