# Dispatch of round()

**URL:** <https://discourse.julialang.org/t/dispatch-of-round/82756>\
**Category:** General Usage\
**Created:** [June 14, 2022, 3:26pm UTC](https://discourse.julialang.org/t/dispatch-of-round/82756 "2022-06-14T15:26:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [June 14, 2022, 3:26pm UTC](https://discourse.julialang.org/t/dispatch-of-round/82756/1 "2022-06-14T15:26:31Z")

</div>

hi here, I have a problem regarding the dispatching of `round()`:

```julia
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:

```julia
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:

```julia
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

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 14, 2022, 4:08pm UTC](https://discourse.julialang.org/t/dispatch-of-round/82756/2 "2022-06-14T16:08:34Z")

</div>

> [@tomtom](#):
>
> ```julia
> 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)
> 
> ```

This defines the method you’re looking for. The second argument has a default value assigned to it.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [June 14, 2022, 4:28pm UTC](https://discourse.julialang.org/t/dispatch-of-round/82756/3 "2022-06-14T16:28:56Z")

</div>

it’s NOT what `@enter` tells me???

```julia
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)

```

it says `round(2.2)` involves the definition in `float.jl`, not that in `floatfuncs.jl` as u mentioned.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 14, 2022, 4:40pm UTC](https://discourse.julialang.org/t/dispatch-of-round/82756/4 "2022-06-14T16:40:18Z")

</div>

> [@tomtom](#):
>
> it’s NOT what `@enter` tells me???

Maybe `@enter` is getting confused by inlining?

```julia
julia> @which round(2.2)
round(x::Real) in Base at floatfuncs.jl:129

```
