I would say all programming languages have functions with these names to choose the lesser or greater of two values:
min()
& max()
floor()
& ceil()
/ ceiling()
And some languages have both. JavaScript I believe is one example.
I've always been a bit fuzzy on the difference between the former pair and the latter pair. I have a vague impression that min
/max
are more simplistic and floor
/ceiling
are more mathematical, but that's not much to go on.
Oddly I can't find this discussed anywhere on StackOverflow or the Internet generally by searching Google. So is there some best practices or rules of thumb to decide which of these functions to use when your programming language offers both?
The ceil function returns the smallest integer value which is greater than or equal to the specified number, whereas the floor function returns the largest integer value which is less than or equal to the specified number.
ceil method returns the smallest integer greater than or equal to the value we pass, Math. floor returns the largest or equal integer that is less than the given value.
The FLOOR function rounds down. The CEIL function rounds up. The ROUND function rounds to the nearest integer.
The ceil() function computes the smallest integer that is greater than or equal to x.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With