# Ceiling division

**URL:** <https://discourse.julialang.org/t/ceiling-division/103467>\
**Category:** General Usage\
**Created:** [September 2, 2023, 6:59pm UTC](https://discourse.julialang.org/t/ceiling-division/103467 "2023-09-02T18:59:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [September 2, 2023, 6:59pm UTC](https://discourse.julialang.org/t/ceiling-division/103467/1 "2023-09-02T18:59:11Z")

</div>

`x ÷ k` is faster than `floor(Int, x/k)`. Is there an ceiling division function that rounds up instead of down, equivalent to but faster than `ceil(Int, x/k)`?

```julia
julia> f(x) = floor(Int, x/4)
f (generic function with 1 method)

julia> g(x) = x÷4
g (generic function with 1 method)

julia> @benchmark f(x) setup = (x=rand())
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max): 6.422 ns … 29.276 ns ┊ GC (min … max): 0.00% … 0.00%
 Time (median): 6.432 ns ┊ GC (median): 0.00%
 Time (mean ± σ): 6.535 ns ± 0.661 ns ┊ GC (mean ± σ): 0.00% ± 0.00%

  █                                                           
  █▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▁▂▂▁▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▂
  6.42 ns Histogram: frequency by time 10.4 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark g(x) setup = (x=rand())
BenchmarkTools.Trial: 10000 samples with 999 evaluations.
 Range (min … max): 8.234 ns … 15.023 ns ┊ GC (min … max): 0.00% … 0.00%
 Time (median): 8.244 ns ┊ GC (median): 0.00%
 Time (mean ± σ): 8.269 ns ± 0.241 ns ┊ GC (mean ± σ): 0.00% ± 0.00%

                            ▁ █ ▅  
  ▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇▁█ ▂
  8.23 ns Histogram: frequency by time 8.25 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

```

---

<div class="post-metadata">

**Author:** ![\_bernhard](https://avatars.discourse-cdn.com/v4/letter/_/bc79bd/32.png) [@\_bernhard](https://discourse.julialang.org/u/_bernhard)\
**Post date:** [September 2, 2023, 7:57pm UTC](https://discourse.julialang.org/t/ceiling-division/103467/2 "2023-09-02T19:57:19Z")

</div>

yes, there is 🙂  
[https://docs.julialang.org/en/v1/base/math/#Base.cld](https://docs.julialang.org/en/v1/base/math/#Base.cld)
