The next step up in sophistication from the arithmetic operators consists of miscellaneous functions that perform tasks like converting between the two numerical types and finding the minimum and maximum of a set of numbers.
Function | Description |
---|---|
floor() |
Takes a single argument (typically a double) and returns the largest integer that is less than or equal to that argument. |
ceil() |
Short for ceiling — takes a single argument (typically a double) and returns the smallest integer that is greater than or equal to that argument. |
round() |
Takes a single argument (typically a double) and returns the nearest integer. If the fractional part is exactly 0.5, it returns the nearest even number. |
abs() |
Short for absolute value — if the single numerical argument is negative, the corresponding positive number is returned; if the argument is positive, the argument itself is returned. |
min() |
Takes any number of numerical arguments (but at least one) and returns the smallest of the arguments. |
max() |
Takes any number of numerical arguments (but at least one) and returns the largest of the arguments. |
For example, the result of the following expression:
min(3, abs(-3), max(round(2.7), ceil(2.3), floor(3.9)))
is 3
, because the value of every function call is also 3.