From 48c12efbf46cbd4143b1c605004bd6224461b3d8 Mon Sep 17 00:00:00 2001 From: Nils Bruin Date: Wed, 17 Feb 2016 16:48:39 -0800 Subject: [PATCH] trac #20064: introduce "argument" on RealIntervalFieldElement --- src/sage/rings/real_mpfi.pyx | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index ddf0aadbfbb..b19e766cc3b 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -3191,6 +3191,45 @@ cdef class RealIntervalFieldElement(RingElement): else: raise ValueError("interval does not have a unique sign") + def argument(self): + r""" + The argument of this interval, if it is well-defined, in the + complex sense. Otherwise raises a ``ValueError``. + + OUTPUT: + + - an element of the parent of this interval (0 or pi) + + EXAMPLES:: + + sage: RIF(1).argument() + 0 + sage: RIF(-1).argument() + 3.141592653589794? + sage: RIF(0,1).argument() + 0 + sage: RIF(-1,0).argument() + 3.141592653589794? + sage: RIF(0).argument() + Traceback (most recent call last): + ... + ValueError: Can't take the argument of an exact zero + sage: RIF(-1,1).argument() + Traceback (most recent call last): + ... + ValueError: Can't take the argument of interval strictly containing zero + + """ + k=self.parent() + if mpfi_is_zero(self.value): + raise ValueError("Can't take the argument of an exact zero") + if mpfi_is_nonneg(self.value): + return k.zero() + elif mpfi_is_nonpos(self.value): + return k.pi() + else: + raise ValueError("Can't take the argument of interval strictly containing zero") + def unique_floor(self): """ Returns the unique floor of this interval, if it is well defined,