hi here, I have a problem regarding the dispatching of round()
:
julia> @enter round(2.2)
[ Info: tracking Base
In round(x, r) at float.jl:380
>380 round(x::Float64, r::RoundingMode{:Nearest}) = rint_llvm(x)
julia> @enter round(2.2; digits = 2)
In #round#708(digits, sigdigits, base, , x, r) at floatfuncs.jl:129
129 function round(x::Real, r::RoundingMode=RoundNearest;
130 digits::Union{Nothing,Integer}=nothing, sigdigits::Union{Nothing,Integer}=nothing, base::Union{Nothing,Integer}=nothing)
in particular, I wonder why calling round(2.2)
would not give an error as the second parameter RoundingMode
is not specified.
in float.jl
see the following definitions:
round(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundNearest))
round(x::Float64, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float32, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float16, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float64, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float32, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float16, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float64, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float32, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float16, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float64, r::RoundingMode{:Nearest}) = rint_llvm(x)
round(x::Float32, r::RoundingMode{:Nearest}) = rint_llvm(x)
round(x::Float16, r::RoundingMode{:Nearest}) = rint_llvm(x)
whereas in floatfuncs.jl
see:
function round(::Type{T}, x::AbstractFloat, r::RoundingMode) where {T<:Integer}
function round(x::Real, r::RoundingMode=RoundNearest;
digits::Union{Nothing,Integer}=nothing, sigdigits::Union{Nothing,Integer}=nothing, base::Union{Nothing,Integer}=nothing)
again, no definition of round(x::Float64) = xxx
is found.
thanks