# 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
|
|
18 | 18 | |
19 | 19 | cdef class RealIntervalField_class(sage.rings.ring.Field): |
20 | 20 | cdef int __prec |
21 | | cdef object print_options |
| 21 | cpdef dict print_options |
22 | 22 | # Cache RealField instances for the lower, upper, and middle bounds. |
23 | 23 | # These have the same precision as the interval field; |
24 | 24 | # __lower_field rounds down, __upper_field rounds up. |
diff -r b8a99f1aa3ea -r 6ca588087d94 sage/rings/real_mpfi.pyx
a
|
b
|
|
227 | 227 | printing_style = 'question' |
228 | 228 | printing_error_digits = 0 |
229 | 229 | |
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} |
232 | 231 | |
233 | 232 | |
234 | 233 | #***************************************************************************** |
… |
… |
|
465 | 464 | deprecation("The sci_not keyword is deprecated. Use scientific_notation instead.") |
466 | 465 | scientific_notation=sci_not |
467 | 466 | |
468 | | self.print_options=_PRINT_OPTIONS.copy() |
469 | 467 | 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={} |
472 | 471 | 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 | |
477 | 478 | self.__lower_field = RealField(prec=prec, rnd="RNDD", |
478 | 479 | print_options=realfield_print_options) |
479 | 480 | self.__middle_field = RealField(prec=prec, rnd="RNDN", |
… |
… |
|
515 | 516 | x.init = 1 |
516 | 517 | return x |
517 | 518 | |
| 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 | |
518 | 542 | def _repr_(self): |
519 | 543 | s = "Real Interval Field with %s bits of precision"%self.__prec |
520 | 544 | return s |
… |
… |
|
921 | 945 | |
922 | 946 | - ``status`` - (bool -) optional flag |
923 | 947 | """ |
924 | | from sage.misc.misc import deprecation |
925 | 948 | 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'] |
928 | 950 | 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 |
931 | 953 | |
932 | 954 | def zeta(self, n=2): |
933 | 955 | """ |
… |
… |
|
1423 | 1445 | sage: RIF(0, 3^-150) |
1424 | 1446 | 1.?e-71 |
1425 | 1447 | """ |
| 1448 | print_options=(<RealIntervalField_class>self._parent).print_options |
1426 | 1449 | if base < 2 or base > 36: |
1427 | 1450 | raise ValueError, "the base (=%s) must be between 2 and 36"%base |
1428 | 1451 | |
… |
… |
|
1440 | 1463 | deprecation("The no_sci keyword is deprecated. Use scientific_notation=%r instead."%deprecated_option[no_sci]) |
1441 | 1464 | scientific_notation=deprecated_option[no_sci] |
1442 | 1465 | if scientific_notation not in [None, 'always','extreme']: |
| 1466 | # TODO: 'never' is not checked above, but is in the error message |
1443 | 1467 | 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 | | |
1447 | 1468 | |
1448 | 1469 | |
1449 | 1470 | if e is None: |
… |
… |
|
1453 | 1474 | e = 'e' |
1454 | 1475 | |
1455 | 1476 | 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 |
1457 | 1483 | if error_digits is None: |
1458 | 1484 | error_digits = printing_error_digits |
1459 | 1485 | |
… |
… |
|
1467 | 1493 | return "[%s .. %s]"%(t1, t2) |
1468 | 1494 | |
1469 | 1495 | 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': |
1471 | 1499 | prefer_sci = True |
1472 | | elif scientific_notation=='extreme': |
1473 | | prefer_sci = False |
1474 | 1500 | else: |
1475 | 1501 | raise ValueError, "scientific_notation must be 'always' or 'extreme'" |
1476 | 1502 | return self._str_question_style(base, error_digits, e, prefer_sci) |