PHP Math Functions

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().
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:
$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 functionsRemove signs and round values up, down, or to a precision.
Trig & hyperbolic
16 functionsAngles, triangles, and hyperbolic functions. Trig functions work in radians.
| Function | Description | Tutorial |
|---|---|---|
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 functionsPowers, roots, exponentials, and logarithms.
| Function | Description | Tutorial |
|---|---|---|
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 functionsPick the smallest or largest value, or keep a value inside a range.
Conversion (base, hex, bin, oct)
7 functionsConvert numbers between binary, octal, decimal, and hexadecimal.
| Function | Description | Tutorial |
|---|---|---|
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 functionsInteger quotients, float division, and floating-point remainders.
Special values (finite, NaN, INF)
3 functionsCheck floats for infinity and not-a-number results.
| Function | Description | Tutorial |
|---|---|---|
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 functionMathematical constants available as functions.
Frequently Asked Questions
Start with abs()
Open the absolute-value guide—syntax, examples, and FAQs.
15 people found this page helpful
