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

Method next_toward

Lib/_pydecimal.py:4993–5026  ·  view source on GitHub ↗

Returns the number closest to a, in direction towards b. The result is the closest representable number from the first operand (but not the first operand) that is in the direction towards the second operand, unless the operands have the same value. >>> c = E

(self, a, b)

Source from the content-addressed store, hash-verified

4991 return a.next_plus(context=self)
4992
4993 def next_toward(self, a, b):
4994 """Returns the number closest to a, in direction towards b.
4995
4996 The result is the closest representable number from the first
4997 operand (but not the first operand) that is in the direction
4998 towards the second operand, unless the operands have the same
4999 value.
5000
5001 >>> c = ExtendedContext.copy()
5002 >>> c.Emin = -999
5003 >>> c.Emax = 999
5004 >>> c.next_toward(Decimal('1'), Decimal('2'))
5005 Decimal('1.00000001')
5006 >>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
5007 Decimal('-0E-1007')
5008 >>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
5009 Decimal('-1.00000002')
5010 >>> c.next_toward(Decimal('1'), Decimal('0'))
5011 Decimal('0.999999999')
5012 >>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
5013 Decimal('0E-1007')
5014 >>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
5015 Decimal('-1.00000004')
5016 >>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
5017 Decimal('-0.00')
5018 >>> c.next_toward(0, 1)
5019 Decimal('1E-1007')
5020 >>> c.next_toward(Decimal(0), 1)
5021 Decimal('1E-1007')
5022 >>> c.next_toward(0, Decimal(1))
5023 Decimal('1E-1007')
5024 """
5025 a = _convert_other(a, raiseit=True)
5026 return a.next_toward(b, context=self)
5027
5028 def normalize(self, a):
5029 """normalize reduces an operand to its simplest form.

Callers 1

test_next_towardMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
next_towardMethod · 0.45

Tested by 1

test_next_towardMethod · 0.76