Ticket #7682: trac-7682-realintervalfield-printing.patch

File trac-7682-realintervalfield-printing.patch, 5.8 KB (added by jason, 11 years ago)

apply on top of previous patch

  • sage/rings/real_mpfi.pxd

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1276882312 18000
    # Node ID 6ca588087d942265523c31c677fef8b2fd2fdda6
    # Parent  b8a99f1aa3ea1215dd315a2c8cfecfc561036cb9
    [mq]: realintervalfield-printing.patch
    
    diff -r b8a99f1aa3ea -r 6ca588087d94 sage/rings/real_mpfi.pxd
    a b  
    1818
    1919cdef class RealIntervalField_class(sage.rings.ring.Field):
    2020    cdef int __prec
    21     cdef object print_options
     21    cpdef dict print_options
    2222    # Cache RealField instances for the lower, upper, and middle bounds.
    2323    # These have the same precision as the interval field;
    2424    # __lower_field rounds down, __upper_field rounds up.
  • sage/rings/real_mpfi.pyx

    diff -r b8a99f1aa3ea -r 6ca588087d94 sage/rings/real_mpfi.pyx
    a b  
    227227printing_style = 'question'
    228228printing_error_digits = 0
    229229
    230 _PRINT_OPTIONS = {'skip_zeroes': False, 'truncate': True, 'scientific_notation': 'extreme',
    231                   'style': 'question', 'error_digits': 0}
     230_PRINT_OPTIONS = {'style': 'question', 'error_digits': 0}
    232231
    233232
    234233#*****************************************************************************
     
    465464            deprecation("The sci_not keyword is deprecated.  Use scientific_notation instead.")
    466465            scientific_notation=sci_not
    467466       
    468         self.print_options=_PRINT_OPTIONS.copy()
    469467        if scientific_notation is not None:
    470             self.print_options['scientific_notation']=scientific_notation
    471 
     468            print_options['scientific_notation']=scientific_notation
     469
     470        self.print_options={}
    472471        realfield_print_options={}
    473         for key in real_mpfr._PRINT_OPTIONS:
    474             if key in self.print_options:
    475                 realfield_print_options[key]=self.print_options[key]
    476 
     472        for key,val in print_options.items():
     473            if key in _PRINT_OPTIONS:
     474                self.print_options[key]=val
     475            else:
     476                realfield_print_options[key]=val
     477           
    477478        self.__lower_field = RealField(prec=prec, rnd="RNDD",
    478479                                                   print_options=realfield_print_options)
    479480        self.__middle_field = RealField(prec=prec, rnd="RNDN",
     
    515516        x.init = 1
    516517        return x
    517518
     519
     520    property print_options:
     521        """
     522        Options for printing a real number.
     523        """
     524        def __get__(self):
     525            """
     526            Get the printing options.
     527            """
     528            return self.print_options
     529
     530        def __set__(self,newval):
     531            """
     532            Set the printing options.
     533            """
     534            self.print_options=newval
     535
     536        def __del__(self):
     537            """
     538            Reset the printing options to be empty.
     539            """
     540            self.print_options={}
     541
    518542    def _repr_(self):
    519543        s = "Real Interval Field with %s bits of precision"%self.__prec
    520544        return s
     
    921945       
    922946        -  ``status`` - (bool -) optional flag
    923947        """
    924         from sage.misc.misc import deprecation
    925948        if status is None:
    926             deprecation("scientific_notation() is deprecated.  Use self.print_options['scientific_notation'] instead")
    927             return self.print_options['scientific_notation']
     949            return self._lower_field().print_options['scientific_notation']
    928950        else:
    929             deprecation("scientific_notation() is deprecated.  Use self.print_options['scientific_notation']=value instead")
    930             self.print_options['scientific_notation'] = status
     951            for f in self._lower_field(), self._upper_field():
     952                f.print_options['scientific_notation']=status
    931953       
    932954    def zeta(self, n=2):
    933955        """
     
    14231445            sage: RIF(0, 3^-150)
    14241446            1.?e-71
    14251447        """
     1448        print_options=(<RealIntervalField_class>self._parent).print_options
    14261449        if base < 2 or base > 36:
    14271450            raise ValueError, "the base (=%s) must be between 2 and 36"%base
    14281451
     
    14401463            deprecation("The no_sci keyword is deprecated.  Use scientific_notation=%r instead."%deprecated_option[no_sci])
    14411464            scientific_notation=deprecated_option[no_sci]
    14421465        if scientific_notation not in [None, 'always','extreme']:
     1466            # TODO: 'never' is not checked above, but is in the error message
    14431467            raise ValueError, "scientific_notation must be one of 'always', 'extreme', or 'never'."
    1444         elif scientific_notation is None:
    1445             scientific_notation = (<RealIntervalField_class>self._parent).print_options.get('scientific_notation',_PRINT_OPTIONS['scientific_notation'])
    1446        
    14471468
    14481469
    14491470        if e is None:
     
    14531474                e = 'e'
    14541475
    14551476        if style is None:
    1456             style = printing_style
     1477            if 'style' in print_options:
     1478                style=print_options['style']
     1479            elif 'style' in self.print_options:
     1480                style=self.print_options['style']
     1481            else:
     1482                style = printing_style
    14571483        if error_digits is None:
    14581484            error_digits = printing_error_digits
    14591485
     
    14671493            return "[%s .. %s]"%(t1, t2)
    14681494       
    14691495        elif style == 'question':
    1470             if scientific_notation=='always':
     1496            if scientific_notation is None or scientific_notation=='extreme':
     1497                prefer_sci = False
     1498            elif scientific_notation=='always':
    14711499                prefer_sci = True
    1472             elif scientific_notation=='extreme':
    1473                 prefer_sci = False
    14741500            else:
    14751501                raise ValueError, "scientific_notation must be 'always' or 'extreme'"
    14761502            return self._str_question_style(base, error_digits, e, prefer_sci)