# PHP 5 Math Functions

The math functions can handle values within the range of integer and float types.The PHP math functions are part of the PHP core. No installation is required to use these functions.

### PHP 5 Math Functions

FunctionDescription
abs()Returns the absolute (positive) value of a number
acos()Returns the arc cosine of a number
acosh()Returns the inverse hyperbolic cosine of a number
asin()Returns the arc sine of a number
asinh()Returns the inverse hyperbolic sine of a number
atan()Returns the arc tangent of a number in radians
atan2()Returns the arc tangent of two variables x and y
atanh()Returns the inverse hyperbolic tangent of a number
base_convert()Converts a number from one number base to another
bindec()Converts a binary number to a decimal number
ceil()Rounds a number up to the nearest integer
cos()Returns the cosine of a number
cosh()Returns the hyperbolic cosine of a number
decbin()Converts a decimal number to a binary number
dechex()Converts a decimal number to a hexadecimal number
decoct()Converts a decimal number to an octal number
exp()Calculates the exponent of e
expm1()Returns exp(x) - 1
floor()Rounds a number down to the nearest integer
fmod()Returns the remainder of x/y
getrandmax()Returns the largest possible value returned by rand()
hexdec()Converts a hexadecimal number to a decimal number
hypot()Calculates the hypotenuse of a right-angle triangle
is_finite()Checks whether a value is finite or not
is_infinite()Checks whether a value is infinite or not
is_nan()Checks whether a value is 'not-a-number'
lcg_value()Returns a pseudo random number in a range between 0 and 1
log()Returns the natural logarithm of a number
log10()Returns the base-10 logarithm of a number
log1p()Returns log(1+number)
max()Returns the highest value in an array, or the highest value of several specified values
min()Returns the lowest value in an array, or the lowest value of several specified values
mt_getrandmax()Returns the largest possible value returned by mt_rand()
mt_rand()Generates a random integer using Mersenne Twister algorithm
mt_srand()Seeds the Mersenne Twister random number generator
octdec()Converts an octal number to a decimal number
pi()Returns the value of PI
pow()Returns x raised to the power of y
rand()Generates a random integer
round()Rounds a floating-point number
sin()Returns the sine of a number
sinh()Returns the hyperbolic sine of a number
sqrt()Returns the square root of a number
srand()Seeds the random number generator
tan()Returns the tangent of a number
tanh()Returns the hyperbolic tangent of a number

PHP supports and comes with many inbuilt math functions, which always comes handy while performing complex calculation rather than writing your own logic for doing mathematical operations, which can be time-consuming.

### PHP 5 Predefined Math Constants

ConstantValueDescriptionPHP Version
INFINFThe infinitePHP 4
M_E2.7182818284590452354Returns ePHP 4
M_EULER0.57721566490153286061Returns Euler constantPHP 4
M_LNPI1.14472988584940017414Returns the natural logarithm of PI: log_e(pi)PHP 5.2
M_LN20.69314718055994530942Returns the natural logarithm of 2: log_e 2PHP 4
M_LN102.30258509299404568402Returns the natural logarithm of 10: log_e 10PHP 4
M_LOG2E1.4426950408889634074Returns the base-2 logarithm of E: log_2 ePHP 4
M_LOG10E0.43429448190325182765Returns the base-10 logarithm of E: log_10 ePHP 4
M_PI3.14159265358979323846Returns PiPHP 4
M_PI_21.57079632679489661923Returns Pi/2PHP 4
M_PI_40.78539816339744830962Returns Pi/4PHP 4
M_1_PI0.31830988618379067154Returns 1/PiPHP 4
M_2_PI0.63661977236758134308Returns 2/PiPHP 4
M_SQRTPI1.77245385090551602729Returns the square root of PI: sqrt(pi)PHP 5.2
M_2_SQRTPI1.12837916709551257390Returns 2/square root of PI: 2/sqrt(pi)PHP 4
M_SQRT1_20.70710678118654752440Returns the square root of 1/2: 1/sqrt(2)PHP 4
M_SQRT21.41421356237309504880Returns the square root of 2: sqrt(2)PHP 4
M_SQRT31.73205080756887729352Returns the square root of 3: sqrt(3)PHP 5.2
NANNANNot A NumberPHP 4
PHP_ROUND_HALF_UP1Round halves upPHP 5.3
PHP_ROUND_HALF_DOWN2Round halves downPHP 5.3
PHP_ROUND_HALF_EVEN3Round halves to even numbersPHP 5.3
PHP_ROUND_HALF_ODD4Round halves to odd numbersPHP 5.3
{"ft_lang_label":"__label__en","ft_lang_prob":0.5064916,"math_prob":0.98078835,"size":4541,"snap":"2023-14-2023-23","text_gpt3_token_len":1465,"char_repetition_ratio":0.23319374,"word_repetition_ratio":0.0625,"special_character_ratio":0.3395728,"punctuation_ratio":0.0546875,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99856263,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-31T19:54:09Z\",\"WARC-Record-ID\":\"<urn:uuid:817230b5-530c-423c-af95-9857f3dfcfcd>\",\"Content-Length\":\"20786\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:38d75b2d-0c3f-45b2-9bcc-44192fde3634>\",\"WARC-Concurrent-To\":\"<urn:uuid:f738adcb-631b-416c-a664-d37407337a86>\",\"WARC-IP-Address\":\"103.93.17.55\",\"WARC-Target-URI\":\"https://www.pustudy.com/php/php_math.html\",\"WARC-Payload-Digest\":\"sha1:B4DQDBZJPUJUHGTTBECJXUUKGOXZTFWP\",\"WARC-Block-Digest\":\"sha1:NAA2J3JFOYYGN6IUD4LQGFM5DB3N6XGI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224647409.17_warc_CC-MAIN-20230531182033-20230531212033-00628.warc.gz\"}"}