COS
COS(X)Here, X represents a numeric expression.
Section titled “COS(X)Here, X represents a numeric expression.”- x: Represents the angle in radians for which the cosine value is to be calculated.
Example
Section titled “Example”SELECT COS(PI());Output
Section titled “Output”-1.0Explanation
Section titled “Explanation”The COS function in MySQL returns the cosine of a number. In the provided example, the number used is the mathematical constant PI. The cosine of PI, in mathematics, is -1, therefore, the output of the function is -1.0.
COS(float_expression)
Section titled “COS(float_expression)”- float_expression: This parameter represents an expression of type float from which the SQL Server derives the cosine. The specified float expression should be from -1 to 1 because cos(x) is defined in these ranges. If NULL is inputted, the output will also be NULL.
Example
Section titled “Example”DECLARE @radian_value FLOAT;SET @radian_value = PI()/3;SELECT COS(@radian_value) as Cosine_Value;Output
Section titled “Output”| Cosine_Value ||---------------------|| 0.500000011324464 |Explanation
Section titled “Explanation”In the SQL code provided, COS() function is used to calculate cosine of the radian value. We first declare a variable and set it to PI()/3 which converts degree to radian. Finally, the COS() function is applied on this radian to get the cosine value. The result returns the cosine value of the radian. In SQL, COS() function returns the cosine of the specified radian value.
COS(n NUMBER) RETURN NUMBER;
Section titled “COS(n NUMBER) RETURN NUMBER;”- n number: This is the numeric value, in degrees, for which the cosine is to be computed. The COS function will return the cosine of this given number.
Example
Section titled “Example”SELECT COS(1) FROM dual;Output
Section titled “Output”0.54030230586814Explanation
Section titled “Explanation”In the example above, the COS function, which computes the cosine of a number, is used to calculate the cosine of 1. The FROM dual clause is necessary in Oracle SQL to select from a dummy table. The result of COS(1) is 0.54030230586814.