What's the difference between the pair of functions floor()/ceil() and min()/max()?

This is apples vs. oranges. In most languages/APIs, min/max take two (or more) inputs, and return the smallest/biggest. floor/ceil take one argument, and round it down or up to the nearest integer.


To my knowledge max and min are used on a collection, say an array of numbers. Floor and ceiling are used for single numbers. For example:

min(1, 2, 3, 4) => 1
max(1, 2, 3, 4) => 4
floor(3.5) => 3
ceiling(3.5) => 4

min(1, 2) == 1
max(1, 2) == 2

floor(3.9) == 3
round(3.9) == 4

ceil(3.1) == 4
round(3.1) == 3

trunc, as in (int)(3.xxx) = 3 (no matter what xxx is)

On the definition:

floor is the greatest integer less than n.

ceil is the smallest integer greater than n.

Tags:

Max

Min

Floor

Ceil