Sunday, June 14, 2026
HomeLanguagesPHP cos( ) Function

PHP cos( ) Function

Trigonometry is an important part of mathematics and PHP’s math functions provides us with some functions which are very useful for calculations involving trigonometry. The cos()function in PHP is used to find the cosine of a number.
The cos() function returns a float value between -1 and 1, which represents the cosine of the angle. The argument passed to it must be in radians.

Syntax:

float cos($value)

Parameters: This function accepts a single parameter value. It is the number whose cosine you want to find. The value must be in radians.

Return Value: It returns a floating point number which is the cosine value of number passed to it as argument.

Examples:

Input : cos(3) 
Output : -0.98999249660045

Input : cos(-3)
Output : -0.98999249660045

Input : cos(2*M_PI)
Output : 1

Input : cos(0) 
Output : 1

Below programs illustrate cos() function in PHP:

  • Passing 3 as a parameter:




    <?php
      
    echo (cos(3));
      
    ?>      

    
    

    Output:

    -0.98999249660045
  • Passing -3 as a parameter:




    <?php
      
    echo (cos(-3));
      
    ?>      

    
    

    Output:

    -0.98999249660045
  • When (2*M_PI) is passed as a parameter, M_PI is a constant in PHP whose value is 3.1415926535898:




    <?php
      
    echo (cos(2*M_PI));
      
    ?>      

    
    

    Output:

    1
  • Passing 0 as a parameter:




    <?php
      
    echo (cos(0));
      
    ?>      

    
    

    Output:

    1

Reference:
http://php.net/manual/en/function.cos.php

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS