Math
25 entries
abs
Returns the absolute value of a number.
base_convert
Arbitrary-base string conversion (2-36 both ways); large numbers lose precision through the internal float (manual warning, verified) - use BCMath/GMP for exactness.
bindec / octdec / decbin / dechex / hexdec (fixed-base quick reference)
Quick reference for the fixed-base conversions between binary/octal/hexadecimal and decimal: bindec/octdec/hexdec parse to decimal, decbin/dechex format from decimal. For arbitrary bases (2-36) see the base_convert entry; the single-function deep dives live in the dechex/hexdec entries.
ceil
Rounds fractions up (ceiling).
clamp
Range clamping (new in PHP 8.6): returns the value when it lies within [min, max], otherwise the nearest bound; min > max throws ValueError.
dechex
Converts a decimal number to its hexadecimal string representation.
deg2rad / rad2deg
Converts between degrees and radians: deg2rad multiplies by pi/180 and rad2deg by 180/pi — the two-way bridge in and out of trigonometric functions.
the exp / log / log10 / log1p family
The transcendental family: exp/log are mutual inverses (log(exp(2)) returns 2), log10 is the common logarithm, and log1p computes log(1+x) accurately even when x is near zero — the contrast experiment "1 + 1e-16 rounds to exactly 1.0 in double" is the heart of this entry.
fdiv
Safe float division (PHP 8.0+): division by zero and invalid input don't throw DivisionByZeroError — IEEE semantics return INF/-INF/NAN.
floor
Rounds down toward negative infinity: floor(-2.5) is -3 while an int cast truncates toward zero giving -2 - the negative-direction trap is the core teaching point paired with ceil.
fmod
Float modulo whose result keeps the sign of the dividend.
hexdec
Converts a hexadecimal string to a decimal number.
hypot
Calculates the hypotenuse of a right-angle triangle (distance from (x, y) to the origin). Mathematically equal to sqrt(x^2+y^2), but it scales before squaring so intermediate values never overflow — the extreme 3e200/4e200 contrast is the heart of this entry: the naive formula squares its way to INF while hypot still returns 5e200.
is_infinite
Checks whether a value is infinite (INF or -INF).
is_nan
Checks whether a value is NaN (not a number).
max
Returns the largest of several values.
min
Returns the smallest of several values.
mt_rand
Mersenne Twister pseudo-random integers: once mt_srand fixes the seed the sequence is fully reproducible — the only randomness entry whose output can be pre-set deterministically.
pow
Raises a number to a power (PHP 8 recommends the `**` operator).
rand
Generates a random integer within a given range.
random_bytes
Generates cryptographically secure random bytes (for tokens, keys, salts and the like).
random_int
Generates a cryptographically secure random integer (both bounds inclusive).
round
Rounds a float to a given precision.
sqrt / pi
Square root and pi: sqrt returns the float square root (negative input yields a silently propagating NAN, not an error), and pi() holds the same double-precision pi as the M_PI constant; under IEEE 754 every language's output matches exactly.
the sin / cos / tan family
Quick reference for the trigonometric family: basic (sin/cos/tan), inverse (asin/acos/atan) and hyperbolic (sinh/cosh/tanh) functions are built in across all languages — and every argument is in radians, not degrees; convert with deg2rad first.