# HG changeset patch
# User was@bsd.local
# Date 1179000261 25200
# Node ID f10d7dcec94da40d14f68cf25a7124dff04e0f44
# Parent  c23d6dc7ac4ba567fda8d7f05cca65f0daabc87a
Added *fast* mpfr __nonzero__; fixed an inefficiency in exact_rational when input is 0.

diff -r c23d6dc7ac4b -r f10d7dcec94d sage/rings/real_mpfr.pyx
--- a/sage/rings/real_mpfr.pyx	Fri May 11 09:52:14 2007 -0700
+++ b/sage/rings/real_mpfr.pyx	Sat May 12 13:04:21 2007 -0700
@@ -1449,12 +1449,19 @@ cdef class RealNumber(sage.structure.ele
             6125652559
             sage: RealField(5)(-pi).exact_rational()
             -25/8
-        """
+            sage: RR(0).exact_rational()
+            0
+        """
+        if mpfr_sgn(self.value) == 0:
+             # Best to do this case directly, since below we'll get an exponent
+             # like, e.g., -1073741823, which results in huge wasted work. 
+             return Rational(0)
+
         cdef Integer mantissa = Integer()
         cdef mp_exp_t exponent
 
         if not mpfr_number_p(self.value):
-            raise ValueError, 'Calling exact_rational() on infinity or NaN'
+            raise ValueError, 'exact_rational not defined on infinity or NaN'
 
         exponent = mpfr_get_z_exp(mantissa.value, self.value)
 
@@ -1873,6 +1880,17 @@ cdef class RealNumber(sage.structure.ele
         else:
             return 1
     
+    def __nonzero__(self):
+        """
+        EXAMPLES:
+            sage: bool(RR(1))
+            True
+            sage: bool(RR(0))
+            False
+            sage: bool(RealField(5)(0))
+	    False
+        """
+        return bool(mpfr_sgn(self.value))
 
     ############################
     # Special Functions
