×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Asin() Function with Examples

Golang | math.Asin() Function: Here, we are going to learn about the Asin() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 29, 2021

math.Asin()

The Asin() function is an inbuilt function of the math package which is used to get the arcsine value (in radians) of the given value.

It accepts one parameter and returns the arcsine.

Syntax

func Asin(x float64) float64

Parameters

  • x : The value whose arcsine value is to be found.

Return Value

The return type of Asin() function is a float64, it returns the arcsine value (in radians) of the given value.

Special cases are:

  • Asin(±0) = ±0
    If the parameter is either positive or negative zero (±0), it returns the same (±0).
  • Asin(x) = NaN if x < -1 or x > 1
    If the parameter is either less than -1 or greater than 1, it returns the NaN.

Example 1

// Golang program to demonstrate the
// example of math.Asin() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Asin(1))
	fmt.Println(math.Asin(0.23))

	fmt.Println(math.Asin(-1))
	fmt.Println(math.Asin(-0.23))

	fmt.Println(math.Asin(-1.23))
	fmt.Println(math.Asin(1.23))

	fmt.Println(math.Asin(-0))
	fmt.Println(math.Asin(0))
}

Output:

1.5707963267948966
0.23207768286271319
-1.5707963267948966
-0.23207768286271319
NaN
NaN
0
0

Example 2

// Golang program to demonstrate the
// example of math.Asin() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var AsinX float64

	x = 0
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)

	x = 0.23
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)

	x = 1
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)

	x = -0.23
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)

	x = -2
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)

	x = 10
	AsinX = math.Asin(x)
	fmt.Println("Arcsine value of", x, "is", AsinX)
}

Output:

Arcsine value of 0 is 0
Arcsine value of 0.23 is 0.23207768286271319
Arcsine value of 1 is 1.5707963267948966
Arcsine value of -0.23 is -0.23207768286271319
Arcsine value of -2 is NaN
Arcsine value of 10 is NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.