PHP Math Functions

Beginner
6 min read
Updated: Nov 2026
45 function guides
Function index

About This Index

This page is the PHP Math Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn ints, floats, and arithmetic on /php/math. Use this page when you need a specific helper such as abs(), round(), or sqrt().

Beginner path.

Start with abs(), round(), sqrt(), and max()—then browse the rest by category.

How to Call a Number Function

PHP math helpers are global functions—pass the number as an argument:

PHP
$n = -7.5;

$abs     = abs($n);              // 7.5
$rounded = round(3.14159, 2);    // 3.14
$root    = sqrt(16);             // 4.0
$biggest = max(3, 9, 5);         // 9

PHP Math Functions Table

All function guides in this PHP tutorial series (45 tutorials in 8 categories).

Absolute & rounding

4 functions

Remove signs and round values up, down, or to a precision.

FunctionDescriptionTutorial
abs()Absolute value of a number.Try it
ceil()Round a number up to the next integer.Try it
floor()Round a number down to the previous integer.Try it
round()Round a float to a given precision.Try it

Trig & hyperbolic

16 functions

Angles, triangles, and hyperbolic functions. Trig functions work in radians.

FunctionDescriptionTutorial
sin()Sine of an angle in radians.Try it
cos()Cosine of an angle in radians.Try it
tan()Tangent of an angle in radians.Try it
asin()Arc sine, returned in radians.Try it
acos()Arc cosine, returned in radians.Try it
atan()Arc tangent, returned in radians.Try it
atan2()Arc tangent of y/x using both signs.Try it
sinh()Hyperbolic sine.Try it
cosh()Hyperbolic cosine.Try it
tanh()Hyperbolic tangent.Try it
asinh()Inverse hyperbolic sine.Try it
acosh()Inverse hyperbolic cosine.Try it
atanh()Inverse hyperbolic tangent.Try it
deg2rad()Convert degrees to radians.Try it
rad2deg()Convert radians to degrees.Try it
hypot()Length of the hypotenuse of a right triangle.Try it

Logs & exponents

8 functions

Powers, roots, exponentials, and logarithms.

FunctionDescriptionTutorial
pow()Raise a number to a power.Try it
fpow()Float power function that follows IEEE rules.Try it
sqrt()Square root of a number.Try it
exp()Calculate e raised to a power.Try it
expm1()Calculate exp(x) - 1 accurately for small x.Try it
log()Natural logarithm, or log in a chosen base.Try it
log10()Base-10 logarithm.Try it
log1p()Calculate log(1 + x) accurately for small x.Try it

Min, max & clamp

3 functions

Pick the smallest or largest value, or keep a value inside a range.

FunctionDescriptionTutorial
min()Lowest value in a set.Try it
max()Highest value in a set.Try it
clamp()Limit a value to a minimum and maximum.Try it

Conversion (base, hex, bin, oct)

7 functions

Convert numbers between binary, octal, decimal, and hexadecimal.

FunctionDescriptionTutorial
base_convert()Convert a number between arbitrary bases.Try it
bindec()Binary string to decimal.Try it
decbin()Decimal to binary string.Try it
hexdec()Hexadecimal string to decimal.Try it
dechex()Decimal to hexadecimal string.Try it
octdec()Octal string to decimal.Try it
decoct()Decimal to octal string.Try it

Division & remainder

3 functions

Integer quotients, float division, and floating-point remainders.

FunctionDescriptionTutorial
intdiv()Integer division of two numbers.Try it
fdiv()Float division that never throws on zero.Try it
fmod()Floating-point remainder of a division.Try it

Special values (finite, NaN, INF)

3 functions

Check floats for infinity and not-a-number results.

FunctionDescriptionTutorial
is_finite()Check that a value is a finite number.Try it
is_infinite()Check for positive or negative infinity.Try it
is_nan()Check for not-a-number.Try it

Constants (pi)

1 function

Mathematical constants available as functions.

FunctionDescriptionTutorial
pi()Value of pi (3.14159...).Try it

Frequently Asked Questions

PHP math functions are built-in math helpers: rounding, absolute value, powers and roots, trigonometry, logarithms, min/max, base conversion, and checks for special float values. You call them by name, such as abs($n) or sqrt($n).
The Math page teaches ints, floats, arithmetic operators, and casting. This index lists every function tutorial so you can open abs(), round(), sqrt(), max(), and the rest.
round() goes to the nearest value at a chosen precision, floor() always rounds down, and ceil() always rounds up. For 3.5 they return 4, 3, and 4 respectively.
Use intdiv() for the whole-number quotient, fdiv() for float division that returns INF or NAN instead of throwing on a zero divisor, and fmod() for the floating-point remainder.
If you are new, read PHP Math first. Then open abs(), round(), sqrt(), and max() from the table below and browse the other categories as you need them.

Start with abs()

Open the absolute-value guide—syntax, examples, and FAQs.

abs() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful