#7682: Customize printing of real numbers
---------------------------+------------------------------------------------
Reporter: jason | Owner: AlexGhitza
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-4.5
Component: numerical | Keywords:
Author: Jason Grout | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
---------------------------+------------------------------------------------
Old description:
> From http://groups.google.com/group/sage-
> support/browse_thread/thread/06756df51d828bf4
>
> {{{
> we probably ought to make this easier to just print the
> first n digits after the decimal by default for RR numbers, or to not
> print out the trailing zeros. I can't imagine telling my students, for
> example, that they need to do '%.3f'%num every time they come across a
> number, especially since they just want to display the equation, not
> format it as a string.
>
> What do people think about this interface?
>
> sage: RR.print_digits=3
> sage: 3.09384
> 3.094
> sage: RR.print_trailing_zeros=False
> sage: RR.print_digits=None
> sage: 3.09384
> 3.09384
>
> Make it something like the RR.scientific_notation flag that is currently
> in use.
> }}}
>
> Additionally, and more flexibly, we could just have something like:
>
> {{{
>
> sage: RR.set_print_format('%.3f')
> sage: RR(pi)
> 3.142
> }}}
>
> or more pythonically
>
> {{{
> sage: RR.print_format = '%.3f'
> sage: RR(pi)
> 3.142
> }}}
New description:
From http://groups.google.com/group/sage-
support/browse_thread/thread/06756df51d828bf4
{{{
we probably ought to make this easier to just print the
first n digits after the decimal by default for RR numbers, or to not
print out the trailing zeros. I can't imagine telling my students, for
example, that they need to do '%.3f'%num every time they come across a
number, especially since they just want to display the equation, not
format it as a string.
What do people think about this interface?
sage: RR.print_digits=3
sage: 3.09384
3.094
sage: RR.print_trailing_zeros=False
sage: RR.print_digits=None
sage: 3.09384
3.09384
Make it something like the RR.scientific_notation flag that is currently
in use.
}}}
Additionally, and more flexibly, we could just have something like:
{{{
sage: RR.set_print_format('%.3f')
sage: RR(pi)
3.142
}}}
or more pythonically
{{{
sage: RR.print_format = '%.3f'
sage: RR(pi)
3.142
}}}
Edit: the interface below does not allow you to set a C format string or
number of digits, but it does provide a framework for setting field-wide
printing options, and wraps the current printing options Sage has
implemented.
--
Comment(by jason):
Paul: I think I understand your comment now. I did not implement the
original suggestion, but instead provided a framework for field-wide
printing options and just wrapped what Sage currently provides. You bring
up some good questions about the design which are out of scope for the
current patch attached. Given this, I think it would be best to either
change the scope of the ticket to reflect what the patch actually does, or
make a new ticket for the patch and keep this ticket around for a design
discussion of how (or whether it is desirable!) to implement the features
described in the description.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7682#comment:29>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.