 Open in App
Not now

# PHP Math Functions (abs, pi, deg2rad, rad2deg, fmod, floor, ceil, round, is_finite, is_infinite)

• Last Updated : 29 Oct, 2022

As you know PHP is a server side script language and is used for creating dynamic web pages. PHP provides a number of built-in math functions which help in performing several operations while dealing with mathematical data. It has nice support for mathematical processing. No installation is required to use these functions. Some examples of mathematical functions in PHP are as follows: 1. abs() : This function takes negative value as input and returns the absolute (positive) value of a integer or float number. Syntax :

`abs(number);`

In this function ‘number’ can be float or integer. Example :

## php

 ``

Output :

`8.4`

2. pi() : This function returns the value of pi. The named constant M_PI is identical to pi(). Syntax :

`pi();`

Example :

## php

 ``

Output :

`3.1415926535898`

3. deg2rad() : This function takes a degree value as input and convert it to a radian value. Syntax :

`deg2rad(number);`

Example :

## php

 ``

Output :

`3.1415926535898`

4. rad2deg() : This function takes a radian value as input and convert it to a degree value. Syntax :

`rad2deg(number);`

Example :

## PHP

 ``

Output :

`180`

5. fmod() : This function takes two arguments as input returns the floating point remainder (modulo) of division of arguments. Syntax :

`fmod(x, y);`

Here, x is dividend and y is divisor. The remainder (r) is defined as: x = i * y + r, for some integer i. If y is non-zero, r has the same sign as x and a magnitude less than the magnitude of y. Example :

## PHP

 ``

Output :

`0.5`

Here, \$r equals 0.5, because 4 * 1.3 + 0.5 = 5.7 (x = i * y + r)   6. floor() : This function takes numeric value as argument and returns the next lowest integer value (as float) by rounding down value if necessary. Syntax :

`floor(\$number);`

Example :

## php

 ``

Output :

```0
5
-6```

7. ceil() : This function takes numeric value as argument and returns the next highest integer value by rounding up value if necessary. Syntax :

`ceil(\$number);`

Example :

## PHP

 ``

Output :

```1
-5```

8. round() : This function takes numeric value as argument and returns the next highest integer value by rounding up value if necessary. Syntax :

`round(number, precision, mode);`

In this, number specifies the value to round, precision specifies the number of decimal digits to round to (Default is 0) and, mode(optional) specifies one of the following constants to specify the mode in which rounding occurs :

• PHP_ROUND_HALF_UP : (set by Default) Rounds number up to precision decimal, when it is half way there. Rounds 1.5 to 2 and -1.5 to -2
• PHP_ROUND_HALF_DOWN : Round number down to precision decimal places, when it is half way there. Rounds 1.5 to 1 and -1.5 to -1
• PHP_ROUND_HALF_EVEN : Round number to precision decimal places towards the next even value.
• PHP_ROUND_HALF_ODD : Round number to precision decimal places towards the next odd value.

Example :

## php

 ``

Output :

```1.96
1242000
10
9
10
9```

9. is_finite() : This function takes any value as argument and checks whether a value is finite or not. It returns TRUE (1) if the specified value is a finite number, otherwise it returns FALSE/NOTHING. The value is a legal finite if it is within the allowed range for a PHP float on this platform. Syntax :

`is_finite(value);`

Example :

## php

 ``

Output :

`1`

10. is_infinite() : This function takes any value as argument and checks whether a value is infinite or not. It returns TRUE (1) if the specified value is a infinite number, otherwise it returns FALSE/NOTHING. The value is a legal infinite if it is outside the allowed range for a PHP float on this platform. Syntax :

`is_infinite(value);`

Example :

## php

 ``

Output :

`1`

My Personal Notes arrow_drop_up