julia> round(1.23456e1, 2)
12.35
julia> signif(1.23456e1, 2)
12.0
If you want to fold signif into round, I think you would need to do it using a keyword argument.
that's not a bad idea. We could use digits/sigdigits?
it is nice to have round(x, abs(n)) indicate digits to the right of the decimal point and round(x, -abs(n)) indicate digits to the left of the decimal point. round uses digits as an arg name at the moment, so a keyword would be sigdigits. Would the logic be that sigdigits determines the value from which to round to +/- digits?
My idea would be to make both digits and sigdigits keyword arguments: you can specify at most one.
is there a way to specify "only one of these may be given" in the signature or does that test have to occur inside the function?
and .. having both as keywords makes sense to me
The main issue is that it makes dispatch and extensions a bit complicated. e.g. if I define a new number type MagicReal, then I can't just define round(::MagicReal). I end up needing a surrogate positional dispatch function (say _round) which gets overloaded instead.
is there a way for us to supply a general purpose sensibly behaving fallback for just such occasions?
maybe an alternative, so other types do not have to stress it
# where {T} written in a white font
round(x::T; digits::Int) = round_with_digits(x, digits)
round(x::T; sigdigits::Int) = round_with_sigdigits(x, sigdigits)
round(x::T; digits::Int, sigdigits::Int) = throw(ErrorException("use either `digits` or `sigdigits`, use of both simultaneously is not supported")
round(x::T, digits::Int) = round_with_digits(x, digits)
One feature that I'd like to have in round is the ability to specify both digits and RoundingMode. Currently we can do round(x, digits) or round(x, roundingmode) but not round(x, digits, roundingmode) or signif(x, digits, roundingmode). Would it be possible to have this option in PR #26670?
It is always beneficial to support RoundingMode. Note that for this situation, some wrapping logic may be needed because Round(x::F,RoundingMode) where {F<:IEEEFloat} usually piggybacks on some chiplevel instructions.
One feature that I'd like to have in
roundis the ability to specify bothdigitsandRoundingMode.
One step ahead: https://github.com/JuliaLang/julia/pull/26670/files#diff-a6b2d98c6bbc2867449a6c3514854ff3R47
Was fixed by #26670
Most helpful comment
One step ahead: https://github.com/JuliaLang/julia/pull/26670/files#diff-a6b2d98c6bbc2867449a6c3514854ff3R47