Skip to content

Commit 3f26a36

Browse files
authored
work on printpoly docstring (#284)
1 parent 59a0f91 commit 3f26a36

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/show.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ end
9090
###
9191

9292
"""
93-
printpoly(io::IO, p::AbstractPolynomial, mimetype = MIME"text/plain"(); descending_powers=false, offset::Int=0)
93+
printpoly(io::IO, p::AbstractPolynomial, mimetype = MIME"text/plain"(); descending_powers=false, offset::Int=0, var=p.var, compact=false, mulsymbol="*")
9494
9595
Print a human-readable representation of the polynomial `p` to `io`. The MIME
9696
types "text/plain" (default), "text/latex", and "text/html" are supported. By
9797
default, the terms are in order of ascending powers, matching the order in
9898
`coeffs(p)`; specifying `descending_powers=true` reverses the order.
9999
`offset` allows for an integer number to be added to the exponent, just for printing.
100-
`var` allows for overriding the variable used for printing. Setting multiplication symbol to `""`
100+
`var` allows for overriding the variable used for printing. Setting `mulsymbol=""`
101101
will avoid an operator being printed. Setting `compact=true` will use a compact style for floating point numbers.
102102
103103
# Examples
@@ -118,6 +118,15 @@ z - z^-1
118118
119119
julia> printpoly(stdout, Polynomial([-1, 0, 1], :z), offset=-1, descending_powers=true, var=:x)
120120
x - x^-1
121+
122+
julia> p = Polynomial([sqrt(i) for i in 1:4])
123+
Polynomial(1.0 + 1.4142135623730951*x + 1.7320508075688772*x^2 + 2.0*x^3)
124+
125+
julia> printpoly(stdout, p, compact=true)
126+
1.0 + 1.41421*x + 1.73205*x^2 + 2.0*x^3
127+
128+
julia> printpoly(stdout, map(x -> round(x, digits=12), p)) # more control on rounding
129+
1.0 + 1.414213562373*x + 1.732050807569*x^2 + 2.0*x^3
121130
```
122131
"""
123132
function printpoly(io::IO, p::P, mimetype=MIME"text/plain"();

0 commit comments

Comments
 (0)