diff --git a/src/gmpy2_mpc.c b/src/gmpy2_mpc.c index aaf954b2..a73fb6ae 100644 --- a/src/gmpy2_mpc.c +++ b/src/gmpy2_mpc.c @@ -263,5 +263,3 @@ static PyTypeObject MPC_Type = GMPy_MPC_NewInit, /* tp_new */ 0, /* tp_free */ }; - - diff --git a/test/test_mpc.py b/test/test_mpc.py index 1f1fdf51..6359d592 100644 --- a/test/test_mpc.py +++ b/test/test_mpc.py @@ -197,3 +197,24 @@ def test_mpc_divmod(): @example(complex(-2)) def test_mpc_hash(c): assert hash(mpc(c)) == hash(c) + + +def test_mpc_exc(): + gmpy2.set_context(gmpy2.ieee(32)) + + ctx = gmpy2.get_context() + ctx.trap_overflow = True + ctx.trap_underflow = True + + c = mpc(0.1 + 0.1j) + + pytest.raises(gmpy2.UnderflowResultError, lambda: c**201) + pytest.raises(gmpy2.OverflowResultError, lambda: c**-201) + + ctx.trap_inexact = True + + pytest.raises(gmpy2.InexactResultError, lambda: mpc('0.1')) + + ctx.trap_invalid = True + + pytest.raises(gmpy2.InvalidOperationError, lambda: mpc(mpfr('nan')))