#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: |
---------------------------+------------------------------------------------
Description changed by jason:
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
> }}}
>
> 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.
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 patches below do not allow you to set a C format string or
number of digits, but they do provide a framework for setting field-wide
printing options, and wrap the current printing options Sage has
implemented (plus a few minor extensions, I think).
--
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7682#comment:30>
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.