Ticket #8720: trac-8720-printing-complex-zero.patch

File trac-8720-printing-complex-zero.patch, 1.6 KB (added by Mike Hansen, 11 years ago)
  • sage/rings/complex_double.pyx

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1271732481 18000
    # Node ID d76b628bbd9cd550bbba242091eb895c9e0a0d3c
    # Parent  638055501d7553a8f91383ffa97d3262202932db
    #8720: Change printing CC(0) and CDF(0) to show numerical precision, as RR and RDF do.
    
    diff --git a/sage/rings/complex_double.pyx b/sage/rings/complex_double.pyx
    a b  
    912912            +infinity + +infinity*I
    913913            sage: CC(CDF(oo,oo))
    914914            +infinity + +infinity*I
     915            sage: CDF(0)
     916            0.0
    915917        """
    916918        if self._complex.dat[0]:
    917919            # real part is nonzero
     
    921923            if self._complex.dat[1]:   # imag is nonzero
    922924                s = ''
    923925            else:
    924                 return '0'            # imag is zero
     926                return double_to_str(self._complex.dat[0]) # imag is zero
    925927           
    926928        cdef double y = self._complex.dat[1]
    927929        if y:
  • sage/rings/complex_number.pyx

    diff --git a/sage/rings/complex_number.pyx b/sage/rings/complex_number.pyx
    a b  
    445445            '3.243f6a8885a30 + 2.b7e151628aed2*I'
    446446            sage: a.str(base=36)
    447447            '3.53i5ab8p5fc + 2.puw5nggjf8f*I'
     448            sage: CC(0)
     449            0.000000000000000
    448450        """
    449451       
    450452        s = ""
     
    460462                    s = s+" + "
    461463            s = s+"%s*I"%y.str(base, truncate=truncate)
    462464        if len(s) == 0:
    463             s = "0"
     465            s = self.real().str(base, truncate=truncate)
    464466        return s
    465467       
    466468    def _latex_(self):