simple math functions

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.

Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Coding, PHP Math and tagged , . Bookmark the permalink.

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s