You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
String formatting with C (sprintf1()) and Python (fmt()) styles
Using string output of any kind, with any formatter, only outputs the result of calling show() on irrational numbers:
julia># Expecting: "3.1415" with some other numbers at the end
julia>format("{:s}", π)
"π = 3.1415926535897..."
One would not expect there to be the definition (π = ) at the front, nor the ellipsis (…) at the end
Using format() with keyword arguments
The 'native' formatter in Formatting.jl (using keyword arguments with format() doesn't produce the expected values for Irrationals even when using other format, and errors when those irrationals have Unicode symbols as definitions.
Firstly, when using stripzeros = false, then no other formatting is done and the standard display() (or is it show()?) method seems to be called:
Secondly, when implicitly (via, e.g., precision) or explicitly setting stripzeros = true, then we get an error if the standard show method would return a string containing Unicode:
julia># Expecting "+3.1416"
julia>format(pi, precision=4, signed=true, stripzeros=true)
ERROR: UnicodeError: invalid character index
inslow_utf8_next(::Array{UInt8,1}, ::UInt8, ::Int64) at ./strings/string.jl:67in next at ./strings/string.jl:96 [inlined]
ingetindex(::String, ::Int64) at ./strings/basic.jl:70infindnext(::String, ::Char, ::Int64) at ./array.jl:839infindfirst(::String, ::Char) at ./array.jl:864in#format#2(::Int64, ::Int64, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::String, ::String, ::Int64, ::Int64, ::String, ::Symbol, ::String, ::Formatting.#format, ::Irrational{:π}) at /Users/nowacki/.julia/v0.5/Formatting/src/cformat.jl:296in (::Formatting.#kw##format)(::Array{Any,1}, ::Formatting.#format, ::Irrational{:π}) at ./<missing>:0
Note this doesn't error when using an 'ASCII irrational:
String formatting with C (
sprintf1()
) and Python (fmt()
) stylesUsing string output of any kind, with any formatter, only outputs the result of calling
show()
on irrational numbers:One would not expect there to be the definition (
π =
) at the front, nor the ellipsis (…
) at the endUsing
format()
with keyword argumentsThe 'native' formatter in Formatting.jl (using keyword arguments with
format()
doesn't produce the expected values for Irrationals even when using other format, and errors when those irrationals have Unicode symbols as definitions.Firstly, when using
stripzeros = false
, then no other formatting is done and the standarddisplay()
(or is itshow()
?) method seems to be called:Secondly, when implicitly (via, e.g.,
precision
) or explicitly settingstripzeros = true
, then we get an error if the standardshow
method would return a string containing Unicode:Note this doesn't error when using an 'ASCII irrational:
Possible fix
I guess one option would be to
convert
toFloat64
orBigFloat
as appropriate, depending on the desired precision.(See the source for all irrationals defined in Base.)
The text was updated successfully, but these errors were encountered: