# Definition of floor

**URL:** <https://discourse.julialang.org/t/definition-of-floor/46337>\
**Category:** New to Julia\
**Created:** [September 9, 2020, 4:15pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337 "2020-09-09T16:15:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [September 9, 2020, 4:15pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337/1 "2020-09-09T16:15:30Z")

</div>

Hi,  
In base/float.jl I don’t understand the definition of floor: [Here](https://github.com/JuliaLang/julia/blob/c10c45104ae882fd8e006880b75c63ac1f6f66bd/base/float.jl#L363)

```nohighlight
floor(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundDown))

```

I don’t get the round. What I understood is: `trunc(.) = round(., RoundDown)` but I am probably missing something.  
Thank you for the help.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [September 9, 2020, 4:37pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337/2 "2020-09-09T16:37:30Z")

</div>

```julia
julia> round(1.5, RoundDown) # You do not want the default: r::RoundingMode=RoundNearest, would get you 2.0
1.0

julia> trunc(Int64, 1.0) # to get you an integer, i.e. get rid of ".0"
1

```

You can do similar to this in most contexts, but the rest, e.g. “where” is to work for any type T (that applies, i.e. subtype of Integer), e.g. Int8, not just Int64. This is good to know for generic code, and the standard library wants to be fully generic.

---

<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:** [September 9, 2020, 4:38pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337/3 "2020-09-09T16:38:14Z")

</div>

> [@remi-garcia](#):
>
> What I understood is: `trunc(.) = round(., RoundDown)` but I am probably missing something

No, [`trunc` uses `RoundToZero`](https://github.com/JuliaLang/julia/blob/c10c45104ae882fd8e006880b75c63ac1f6f66bd/base/floatfuncs.jl#L154).

```julia
julia> floor(-1.4)
-2.0

julia> trunc(-1.4)
-1.0

```

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [September 9, 2020, 4:49pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337/4 "2020-09-09T16:49:47Z")

</div>

Thanks for the precision, it took me some time to be familiar with `where T` notations.

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [September 9, 2020, 4:50pm UTC](https://discourse.julialang.org/t/definition-of-floor/46337/5 "2020-09-09T16:50:52Z")

</div>

Now that you say it… I forgot the negative numbers 🤦🏻‍♂️. Whoops. Thank you!
