cld
cld(x, y)
Smallest integer larger than or equal to x/y
.
Examples
The cld
function in Julia calculates the smallest integer larger than or equal to the division of x
by y
.
jldoctest
julia> cld(10, 3)
4
julia> cld(5, 2)
3
Here are a few examples of how cld
can be used:

Calculate the number of iterations needed:
julia> total_elements = 15; julia> batch_size = 4; julia> num_iterations = cld(total_elements, batch_size); julia> num_iterations 4
In this example,
cld
is used to calculate the number of iterations required to processtotal_elements
in batches of sizebatch_size
. 
Determine the number of rows in a matrix:
julia> num_elements = 12; julia> num_columns = 4; julia> num_rows = cld(num_elements, num_columns); julia> num_rows 3
Here,
cld
is used to determine the number of rows needed to storenum_elements
in a matrix withnum_columns
.  Handle fractionbased calculations:
julia> numerator = 7; julia> denominator = 2; julia> result = cld(numerator, denominator); julia> result 4
This example demonstrates the use of
cld
with noninteger inputs. It calculates the smallest integer larger than or equal to the division ofnumerator
bydenominator
.
Common mistake example:
julia> cld(10, 0)
ERROR: DivError: integer division error
In this example, the denominator is zero, which results in a division error. Make sure to avoid dividing by zero when using the cld
function.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.