Sin()
function is used to find the sine of the given radian input (x
– parameter) in Go language. The standard math package of Go programming language has Sin()
function.
Syntax of Sin()
Function in Go Language
The syntax of
Sin()
function in Go Language is:
func Sin(x float64) float64
Note: float64
is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Sin(±0) = ±0
Sin(±Inf) = NaN
Sin(NaN) = NaN
Parameters of Sin()
Function in Go Language
x
– Where x
is any Valid float64
Input value in radians. This parameter is required.
Error Handling
If the
If there is no argument (
x
parameter is not a number (numeric value) Sin()
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 Sin()
Function in Go Language
Sin()
function will return the sine of the given input(x
– parameter).
GoLang Sin()
Function Example 1
package main import "fmt" import "math" func main() { var x float64 x = math.Sin(-3.79) fmt.Println(x) }
Output:
0.6039177530112606
GoLang Sin()
Function Example 2
package main import "fmt" import "math" func main() { var x float64 x = math.Sin(12.6) fmt.Println(x) }
Output:
0.03362304722113669
GoLang Sin()
Function Example 3
package main import "fmt" import "math" func main() { var x float64 x = math.Sin(9) fmt.Println(x) }
Output:
0.4121184852417566