Categories
PHP

Trigonometry, Exponential and Logarithmic Functions

PHP supports the set of trigonometry functions, the PHP’s mathematical library also includes the exponential and logarithmic functions.

Trigonometry Functions

These functions are used in geometric calculations to determine the size of angles. They all return radian values:

  1. sin( $num )
    Returns the sine of $num in radians.
  2. cos( $num )
    Returns the cosine of $num in radians.
  3. tan( $num )
    Returns the tangent of $num in radians
  4. asin( $num )
    Returns the arc sine of $num in radians.
  5. acos( $num )
    Returns the arc cosine of $num in radians.
  6. atan( $num )
    Returns the arc tangent of $num in radians.
  7. atan2( $y, $x)
    Returns arc tangent of $x/$y where the sign of both parameters determines the quadrant of the result.

These functions convert values between radians and degrees.

  1. deg2rad( $num )
    Converts the $num from degrees to radians and returns the result.
  2. rad2deg( $num )
    Converts the $num from radians to degrees and returns the result.

Square Root, PI, and Power

  1. pi()
    Returns pie value 3.14159265359.
  2. pow( $num, $exponent )
    $num raised to the power of $exponent. If both parameters are non-negative integers and the result can be represented as an integer, the result will be returned with int type, otherwise it will be returned as a float.
  3. sqrt( $num )
    Returns the square root of $num.

Logarithm Functions

  1. exp( $num )
    Returns e raised to the number power. e is the base of the natural system of logarithms, or approximately 2.718282. For example, the echo exp(5.7); returns 298.87.
  2. log( $num, $base = M_E)
    Returns the natural logarithm of $num. If the optional base parameter is specified, it returns log$base $num.
  3. log10( $num )
    Base-10 logarithm of $num.

Doing Math:

  1. Finding absolute value, lowest value, and highest value
  2. Using Ceil, Floor, and Round functions
  3. Generating random numbers
  4. Converting numbers between decimal, binary, octal, and hexadecimal
  5. Trigonometry, Exponential and Logarithmic Functions