(Translated by https://www.hiragana.jp/)
PHP Math Functions Complete Reference - GeeksforGeeks
Open In App

PHP Math Functions Complete Reference

Last Updated : 22 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The predefined math functions in PHP are used to handle the mathematical operations within the integer and float types. These math functions are part of the PHP core. 

Installation: These functions have not required any installation. The complete list of PHP math functions are given below:

Example: Programs illustrate the decbin() function in PHP:

PHP




<?php
echo decbin(12);
?>


Output:

1100
 

The complete list of Math Functions are given below:

PHP math Function

Description

Example

abs() Return the absolute (positive) value of a number.
Try

acos() Find the arc cosine of a number in radians.
Try

acosh() Find the inverse hyperbolic cosine of a number passed to it as an argument. 
Try

asin() Find the arc sine of a number in radians.
Try

asinh() Find the inverse hyperbolic sine of a number passed to it as an argument.
Try

atan2() Calculate the arc tangent of two variables x and y passed to it as arguments.
Try

atan() Return tangent of an argument passed to it which has as a numeric value between -Pi/2 and Pi/2 radians.
Try

atanh() Return tangent of a number passed to it as an argument.
Try

base_convert() Convert a number given in an arbitrary base to a desired base.
Try

bindec() Return the decimal equivalent of the binary number
Try

ceil() This is used to round a number to the nearest greater integer.
Try

cos() Find the cosine of a number.
Try

cosh() Find the hyperbolic sine of an angle.
Try

decbin() Return a string containing a binary representation of the given decimal number argument.
Try

dechex() Convert a given decimal number to an equivalent hexadecimal number.
Try

decoct() Return the octal equivalent of a decimal number.
Try

deg2rad() Convert from degrees to radian, this is where the method deg2rad() comes in aid.
Try

exp() Calculate e raised to the power of the given argument.
Try

expm1()  Calculate e raised to the power of the given argument minus one.
Try

fmod() Calculate the Modulo of any division 
Try

hexdec() Converts a hexadecimal number to a decimal number
Try

hypot() Returns the square root of sum of the an square of arguments passed
Try

intdiv() Returns the integer quotient of the division of the given dividend and divisor. 
Try

is_finite() Check whether a given input value is finite or not.
Try

is_infinite() Takes a single parameter which is a float that is to be checked.
Try

is_nan() Checks whether a value is ‘not a number’.
Try

log10() Calculates the base 10 logarithm of a number
Try

log() Calculates the base 10 logarithms of a number
Try

max() Return the maximum value in an array.
Try

min() Return the lowest value in an array. 
Try

mt_rand() Generates a random integer between the specified minimum and maximum values
Try

octdec() Calculate the decimal equivalent of an octal number. 
Try

pi() Return the value of πぱい.
Try

pow() It is used with a number raised to any value.
Try

rad2deg() Represents an angle in Radians.
Try

rand()  Generate a random integer. 
Try

round( Round a floating-point number
Try

sin() Find the sine value of a number.
Try

sinh() Find the hyperbolic sine of an angle.
Try

sqrt() Calculate the square root of a number. 
Try

srand() Seed the random number generator rand(). 
Try

tan() Find the tangent of the argument parameter.
Try

tanh() Find the hyperbolic tangent of an angle passed to it as a parameter.
Try



Previous Article
Next Article

Similar Reads

PHP Calendar Functions Complete Reference
The calendar extension contains a series of functions to represent the calendar date into a different format. The standard date is based on Julian Day Count. The date count starting from January 1st, 4713 B.C. is known as Julian Day Count. First, the date is converted into Julian Day Count and then converted into a calendar system. Example: The pro
2 min read
PHP Gmagick Functions Complete Reference
Gmagick is the PHP extension used to create, modify and obtain meta information of an image using GraphicsMagick API. The Gmagick consists of Gmagick, GmagickDraw, and GmagickPixel class. Example: Below programs illustrate the Gmagick::getpackagename()Function in PHP: Original Image: C/C++ Code <?php // Create new Gmagick object $im = new Gmagic
3 min read
PHP Ds\Deque Functions Complete Reference
A deque data structure is used to store the sequence of values in a contiguous memory buffer which grows and shrinks automatically. The deque is the abbreviation of "double-ended queue". Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structure by using the PECL extens
3 min read
PHP Ds\Set Functions Complete Reference
Set is the collection of unique values. The implementation of Ds\Set is similar to the Ds\Map which creates a hash table. The values of Ds\Set are used as key and the mapped values are ignored. Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structure by using the PECL
2 min read
PHP Ds\Map Functions Complete Reference
A Map is a sequential collection of key-value pair which is very similar to the array. The key of a map can be of any type and it is unique. If any value added to the same key in a Map then the map value will replace. It is the efficient Data Structure in PHP 7 to provide the alternative of an array. Requirements: PHP 7 is required for both extensi
3 min read
PHP Filesystem Functions Complete Reference
The Filesystem function is used to access and manipulate filesystem. It is the part of PHP code so no need to install these functions. For accessing the files on the system, the file path will be used. On Unix system, forward slash (/) is used as a directory separator and on Windows platform, both forward slash (/) and backward slash (\) will be us
4 min read
PHP Image Processing and GD Functions Complete Reference
Image processing and GD functions are used to create and manipulate image files in different image formats including GIF, PNG, JPEG, WBMP, and XPM. PHP can deliver the output image directly to the browser. The image processing and GD functions are used to compile the image functions for this work. It can also require other libraries, depending on t
3 min read
PHP GMP Functions Complete Reference
The GMP function uses arbitrary-length integers to perform mathematical operations. The GMP function contains the GMP number as an argument. Example: Program to perform the division of GMP numbers when numeric strings as GMP numbers are passed as arguments. C/C++ Code <?php // PHP program to perform division of // GMP numbers passed as arguments
3 min read
PHP String Functions Complete Reference
Strings are a collection of characters. For example, 'G' is the character and 'GeeksforGeeks' is the string. Installation: These functions are not required any installation. These are the part of PHP core. The complete list of PHP string functions are given below: Example: This program helps us to calculate a 32-bit CRC for the string “Hello World”
6 min read
PHP Imagick Functions Complete Reference
The Imagick Function is used to create and modify images using the ImageMagick API. ImageMagick is the software suite to create edit and modify the composing bitmap images. Thisread, writes and converts images in many formats including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Requirements: PHP 5.1.3 and ImageMag
6 min read
PHP IntlChar Functions Complete Reference
IntlChar() functions provide access of utility methods which is used to access the information about Unicode characters. The IntlChar methods and constants are close to the names and behavior which are used by ICU (International Components for Unicode) library. Example: programs illustrate the IntlChar::charFromName() function in PHP C/C++ Code
4 min read
PHP ImagickDraw Functions Complete Reference
The ImagickDraw class is used to draw the vector-based image using ImageMagick. The vector-based generated image can be saved into the file. Syntax: bool ImagickDraw::s() Example: Below program illustrates the ImagickDraw::point() Function in PHP: C/C++ Code <?php // Create an ImagickDraw object $draw = new \ImagickDraw(); // Set the filled colo
3 min read
PHP Ds\Sequence Functions Complete Reference
A Sequence is used to arrange the values in a single and linear dimension way. In some languages, the sequence refers to the List. The sequence is similar to the array which is used as incremental integer keys are listed below: The index value of the sequence are [0, 1, 2, …, size - 1], where size represents the size of the array.The sequence eleme
3 min read
PHP Ds\Vector Functions Complete Reference
A Vector Data Structure is used to store the sequence of values in a contiguous memory buffer which grows and shrinks automatically. The vector data structure mapped the index value to its index buffer and the growth factor isn't bound to a specific multiple or exponent. It is the efficient Data Structure in PHP 7 to provide the alternative of an a
3 min read
PHP Ds\Stack Functions Complete Reference
Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). The Ds\Stack uses Ds\Vector internally. Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structur
2 min read
PHP Ds\Queue Functions Complete Reference
A Queue is a linear data structure that follows a particular order in which the operations are performed. The order of queue is First In First Out (FIFO). Requirements: PHP 7 is required for both extension and the compatibility polyfill. Installation: The easiest way to install data structure by using the PECL extension. pecl install ds Syntax: pub
2 min read
PHP Ds\PriorityQueue Functions Complete Reference
PriorityQueue is similar to a Queue data structure. The elements of the priority queue are pushed into the queue with a given priority. The highest priority element will always been present at the front of the queue. The priority queue is implemented using the max heap. Requirements: PHP 7 is required for both extension and the compatibility polyfi
2 min read
PHP DOM Functions Complete Reference
PHP DOM extension is used to operate on XML documents using DOM API. The DOM extension uses UTF-8 encoding. The Complete list of PHP DOM Functions are listed below: DOMAttr PHP DOMAttr __construct() FunctionPHP DOMAttr isId() Function DOMCdataSection PHP DOMCdataSection __construct() Function DOMCharacterData PHP DOMCharacterData appendData() Funct
2 min read
PHP intl Functions Complete Reference
The Complete list of PHP intl Functions are listed below: Collator PHP collator_asort() FunctionPHP collator_compare() FunctionPHP Collator __construct() FunctionPHP Collator create() FunctionPHP collator_sort_with_sort_keys() FunctionPHP collator_sort() Function IntlCalendar PHP IntlCalendar add() FunctionPHP IntlCalendar after() FunctionPHP IntlC
1 min read
p5.js Math Complete Reference
The Math object in p5.js is used to perform mathematical operations on numbers. There are many math objects exists in p5.js which are listed below. Calculation Description abs()abs() function is used to calculate the absolute value of a number. ceil()ceil() function is used to calculate the ceil value of a number. constrain()It is used to constrain
3 min read
TensorFlow.js Operations Basic Math Complete Reference
TensorFlow.js is an open-source JavaScript library designed by Google to develop Machine Learning models and deep learning neural networks. TensorFlow.js Operations Basic Math Functions: TensorFlow.js tf.abs() FunctionTensorFlow.js tf.acos() FunctionTensorFlow.js tf.acosh() FunctionTensorFlow.js tf.asin() FunctionTensorFlow.js tf.asinh() FunctionTe
1 min read
Lodash Math Complete Reference
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. It provides us with various inbuilt functions and uses a functional programming approach which makes coding in javascript easier to understand because instead of writing repetitive functions, tasks can be accom
2 min read
CSS Functions Complete Reference
CSS functions are used to set the various CSS property. For example, the attr() function is used to retrieve the value of the HTML attribute. Example: Below example illustrates the radial-gradient() function in CSS: C/C++ Code <!DOCTYPE html> <html> <head> <title>CSS Gradients</title> <style> #main { height: 250p
4 min read
Underscore.js Functions Complete Reference
Underscore.js is a lightweight JavaScript library and not a complete framework that was written by Jeremy Ashkenas that provides utility functions for a variety of use cases in our day-to-day common programming tasks. Underscore provides a number of functions that can be applied to the elements. These include the ability to bind a function to an ob
2 min read
PHP Math Functions (is_nan, pow, sqrt, exp, log, log10, log1p, max, min, getrandmax, rand, mt_rand)
11. is_nan() : This function takes any value as argument and checks whether a value is number or not. It returns TRUE (1) if the specified value is 'not a number', otherwise it returns FALSE/NOTHING. Syntax : is_nan(value); Example : C/C++ Code &lt;?php echo is_nan(234) . &quot;\n&quot;; echo is_nan(asin(1.1)) ; ?&gt; Output : 1 Not
4 min read
PHP Math Functions (abs, pi, deg2rad, rad2deg, fmod, floor, ceil, round, is_finite, is_infinite)
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 mathemat
4 min read
PHP SPL Data structures Complete Reference
Standard PHP Library (SPL) the collection of standard data structures. The SPL data structure grouped the contents according to their implementation. Example: Below programs illustrate the SplDoublyLinkedList::offsetGet() function in PHP: C/C++ Code <?php // Declare an empty SplDoublyLinkedList $list = new \SplDoublyLinkedList; // Use SplDoublyL
4 min read
JavaScript Math Reference
JavaScript Math object is used to perform mathematical operations on numbers. Math is an inbuilt object that works with numbers types but it does not work with BigInt. Example: Below example will give you a brief idea of JavaScript math objects. C/C++ Code // Return PI value(3.141592653589793) console.log(Math.PI); Output: This will print the value
4 min read
How to find min/max values without Math functions in JavaScript ?
In this article, we will learn how to find the minimum and maximum values in an array without using Math functions. We know that Math.max() returns the maximum number passed in an array whereas Math.min() returns the minimum number passed. Approach: The same functionality of the Math functions can be implemented using a loop that will iterate the n
3 min read
Less.js Math Functions
In this article, we will see the various Math functions that are provided by Less.js to perform various mathematical functions as per the user's requirements within CSS code only. Less.js (Leaner Style Sheets) is an extension to normal CSS which basically enhances the abilities of normal CSS and gives superpowers to it. LESS.js provides the built-i
6 min read
Practice Tags :
three90RightbarBannerImg