GoLang – Find Cosine – Cos() Function – Examples & Explanation

Cos() function is used to find the cosine of the given input (x – parameter) in Go language.
The standard math package of Go programming language has Cos() function. The purpose of this function is to show the cosine of the argument x (where x is a radian value).

Syntax of Cos() Function in Go Language

The syntax of Cos() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Cos(±Inf) = NaN
Cos(NaN) = NaN


Parameters of Cos() Function in Go Language

x – Where x is any Valid Input value in radians. This parameter is required.


Error Handling

If the x parameter is not a number (numeric value) Cos() function returns an error .
If there is no argument (x – input value) passes to the function, then the compiler will produce an error.


Return Value of Cos() Function in Go Language

Cos() function will return the cosine of the given input(x – parameter in radian).


GoLang Cos() Function Example 1



GoLang Cos() Function Example 2



GoLang Cos() Function Example 3