
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP acos() Function
Definition and Usage
The acos() function Returns the arc cosine or cos inverse of arg in radians. acos() is the inverse function of cos(). Therefore if cos(x)=y, acos(y)=x.
For example, cos(pi/2)=0 and acos(0)=1.57079633 rad which is equal to pi/2.
This function returns a float value.
Syntax
acos ( float $arg ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 | arg A floating point number whose arc cosine is to be calculated. Number should be withing -1 to 1 |
Return Values
PHP acos() function returns arc cosine of given number. It is angle represented in radians.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates acos(0.5) and returns 1.04719755 radians which is equivalent to pi/3 −
<?php $arg=0.5; $val=acos($arg); echo "acos(" . $arg . ") = " . $val . " radians"; ?>
Output
This will produce the following result −
acos(0.5) = 1.0471975511966 radians
Example
Following example calculates acos(0) and returns 1.5707963267949 radians which is equivalent to pi/2 −
<?php $arg=0; $val=acos($arg); echo "acos(" . $arg . ") = " . $val . " radians"; ?>
Output
This will produce the following result −
acos(0) = 1.5707963267949 radians
Example
Let's check find out acos(-1). It returns 3.14159265 radians (which is pi) −
<?php $arg=-1; $val=acos($arg); echo "acos(" . $arg . ") = " . $val . " radians"; ?>
Output
This will produce the following result −
acos(-1) = 3.1415926535898 radians
Example
The following example returns NAN as the argument number is not within -1 to 1.
<?php $arg=5; $val=acos($arg); echo "acos(" . $arg . ") = " . $val . " radians"; ?>
Output
This will produce the following result −
acos(5) = NAN radians
- Related Articles
- acos() function in PHP
- acos() function in C++ STL
- acos() function for complex number in C++?
- PHP Function arguments
- PHP abs() Function
- PHP acosh() Function
- PHP asin() Function
- PHP asinh() Function
- PHP atan() Function
- PHP atan2() Function
- PHP atanh() Function
- PHP base_convert() Function
- PHP bindec() Function
- PHP ceil() Function
- PHP cos() Function
