Sorry, noob question here.
Julia's signif() in base 10 gives me roundoff errors I don't like to see. I
suppose they are just artifacts of base-2 / base-10 conversions, but I
would still prefer that when I type e.g. signif(1.2,2) I got 1.2 on screen
rather than 1.2000000000000002. Sometimes the errors are in defect, like
signif(1.0,6) giving 0.9999999999999999.
Say I write a new method that gives 1.2 or 1.0 as I like, and I auto-load
it on startup via .juliarc.jl:
function signif(x::Float64, digits::Integer)
# my method here
end
Since the argument types are more specific (Julia's signif() does not even
specify the type of the first input argument x), my method will be
dispatched if x::Float64.
However, at least at my REPL, now the same command signif(1.2,2) that used
to return 1.2000000000000002, will start to return 1.2. Even if this is
more to my liking, can I break other packages that use signif(), or cause
them to behave differently? Or will they all call signif() with its prefix
Base.signif() (or whatever "using" command), so they will behave the same?
I hope my question makes some sense, and thanks in advance.
P.S. If the result of the same command signif(1.2,2) can indeed change
within packages, AND if that is generally not a good idea, I guess I can do
something like this, so as to still use the same function name signif():
function signif(x::Float64, digits::Integer, isnewmethod::Bool=0)
if isnewmethod
# my method here
else
return signif(x,digits,10) # Julia's signif() in base 10
end
end