NumericIO.jl
NumericIO.jl copied to clipboard
Modifying Julia-internal format
I sadly haven't found any Matlab-like „format“ command. Would you extend your code, so that it could be used in the REPL for every number as standard output format? Or does this need involvement of the Julia developers?
Interesting question:
I think I would have to overwrite the default show()/print() method (still not exactly certain which one of the two) for Float64/Float32/....
I do not believe it is considered acceptable to overwrite methods in Julia as is the case for other languages. It only appears to be acceptable to extend a function with additional methods.
I will have to think about it more....
What you could do I think this issue might indeed have to be brought up with the Julia devlopers: Code from NumericIO could indeed be used to add "more control" to Julia's core numeric output. It might also be acceptable to set a default precision/output format in the REPL, etc. I just have not seen much interest in this idea/module yet.
For the moment You can at least define a shorthand to make it less painful to generate SI output:
SI(x) = formatted(x, :SI, ndigits=4)
SI(3.14159e-9) # => "3.142n"
To get rid of the quotes in the output (because the output is of type String): You would probably have to create a thin wrapper object that implements its own show() method.
I just added a section: https://github.com/ma-laforge/NumericIO.jl/blob/master/README.md#Sample_Applications
One thing you could do is add something similar to the following to your ~/.juliarc.jl file:
using NumericIO
Base.display(r::Base.REPL.REPLDisplay, v::Union{Float32,Float64}) = print(formatted(Base.REPL.outstream(r.repl), :SI, ndigits=4), v)
...But this only works to display floating-point results on the Julia console. This is not a complete solution.
Since this solutions are suboptimal, I'll file a feature request in Julia. :)
// JuliaLang/julia#19824