Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

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


Output:
0.5253219888177297

 

GoLang Cos() Function Example 2


Output:
1

 

GoLang Cos() Function Example 3


Output:
0.994300732549815

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved