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