Skip to content

Commit 5c5e621

Browse files
committed
Test an infinite divisor
1 parent 383fc62 commit 5c5e621

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎Lib/test/test_decimal.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,21 @@ def test_divide_int_overflow(self):
33183318
self.assertEqual(c.remainder(a, b), Decimal('0.00'))
33193319
self.assertFalse(any(c.flags.values()))
33203320

3321+
def test_divide_int_infinite_divisor(self):
3322+
Decimal = self.decimal.Decimal
3323+
Context = self.decimal.Context
3324+
3325+
# A finite number divided by an infinity is an exact zero: it is
3326+
# neither clamped nor rounded, even where clamping would apply.
3327+
with self.decimal.localcontext(
3328+
Context(prec=4, Emax=2, Emin=-4, clamp=1, traps=[])) as c:
3329+
a, b = Decimal('-8.91'), Decimal('Infinity')
3330+
for op in (c.divide_int, lambda x, y: c.divmod(x, y)[0],
3331+
operator.floordiv, lambda x, y: divmod(x, y)[0]):
3332+
c.clear_flags()
3333+
self.assertEqual(str(op(a, b)), '-0')
3334+
self.assertFalse(any(c.flags.values()))
3335+
33213336
def test_exp(self):
33223337
Decimal = self.decimal.Decimal
33233338
Context = self.decimal.Context

0 commit comments

Comments
 (0)