Cos()
The Cos()
function returns the cosine of the given angle (in radians). The math
library must be imported in order to use this function.
Syntax
result := math.Cos(angle)
Where result
is the cosine value of angle
, returned as a float, except under the following circumstances:
- The result of
Cos(-Inf)
isNaN
- The result of
Cos(+Inf)
isNaN
- The result of
Cos(NaN)
isNaN
Example
The following calculates the cosine of angle
and prints out the result:
package mainimport ("fmt""math")func main() {angle := math.Pi / 6cosine := math.Cos(angle)fmt.Printf("%.1f\n", cosine)}
The output will be:
0.9
Codebyte Example
The following example is runnable and shows how the Cos()
function handles infinite values.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.