#7356: fixed latex representation for floats
--------------------------------+-------------------------------------------
Reporter: robert.marik | Owner: AlexGhitza
Type: enhancement | Status: new
Priority: minor | Milestone: sage-4.2.1
Component: basic arithmetic | Keywords:
Work_issues: | Author:
Reviewer: | Merged:
--------------------------------+-------------------------------------------
Floats have no LaTeX representation and are formated using str function.
Thus output of latex(float(1e25)) is '1e+25' and not '1 \times 10^{25}'.
The solution is to define function to handle this like the function below
{{{
def float_function(x):
r"""
Returns the LaTeX code for a float ``x``.
INPUT: ``x`` - float number
EXAMPLES::
sage: from sage.misc.latex import float_function
sage: float_function(float(123.05))
'123.05'
sage: float_function(float(3e-15))
'3 \\times 10^{-15}'
sage: float_function(float(3.2e25))
'3.2 \\times 10^{25}'
sage: float_function(float(3.2e+15))
'3.2 \\times 10^{15}'
The output is in some cases shorter than latex method for real
numbers.
sage: float_function(float(1e+15))
'1 \\times 10^{15}'
"""
s = str(x)
parts = s.split('e')
if len(parts) > 1:
# scientific notation
if parts[1][0] == '+':
parts[1] = parts[1][1:]
s = "%s \\times 10^{%s}" % (parts[0], parts[1])
return s
}}}
Will post simple patch, provided it passes tests.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7356>
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
-~----------~----~----~----~------~----~------~--~---