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

Method next_toward

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

Returns the number closest to self, in the direction towards other. The result is the closest representable number to self (excluding self) that is in the direction towards other, unless both have the same value. If the two operands are numerically equal, then

(self, other, context=None)

Source from the content-addressed store, hash-verified

3552 context)
3553
3554 def next_toward(self, other, context=None):
3555 """Returns the number closest to self, in the direction towards other.
3556
3557 The result is the closest representable number to self
3558 (excluding self) that is in the direction towards other,
3559 unless both have the same value. If the two operands are
3560 numerically equal, then the result is a copy of self with the
3561 sign set to be the same as the sign of other.
3562 """
3563 other = _convert_other(other, raiseit=True)
3564
3565 if context is None:
3566 context = getcontext()
3567
3568 ans = self._check_nans(other, context)
3569 if ans:
3570 return ans
3571
3572 comparison = self._cmp(other)
3573 if comparison == 0:
3574 return self.copy_sign(other)
3575
3576 if comparison == -1:
3577 ans = self.next_plus(context)
3578 else: # comparison == 1
3579 ans = self.next_minus(context)
3580
3581 # decide which flags to raise using value of ans
3582 if ans._isinfinity():
3583 context._raise_error(Overflow,
3584 'Infinite result from next_toward',
3585 ans._sign)
3586 context._raise_error(Inexact)
3587 context._raise_error(Rounded)
3588 elif ans.adjusted() < context.Emin:
3589 context._raise_error(Underflow)
3590 context._raise_error(Subnormal)
3591 context._raise_error(Inexact)
3592 context._raise_error(Rounded)
3593 # if precision == 1 then we don't raise Clamped for a
3594 # result 0E-Etiny.
3595 if not ans:
3596 context._raise_error(Clamped)
3597
3598 return ans
3599
3600 def number_class(self, context=None):
3601 """Returns an indication of the class of self.

Callers 1

next_towardMethod · 0.45

Calls 10

_check_nansMethod · 0.95
_cmpMethod · 0.95
copy_signMethod · 0.95
next_plusMethod · 0.95
next_minusMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85
_isinfinityMethod · 0.80
_raise_errorMethod · 0.80
adjustedMethod · 0.80

Tested by

no test coverage detected