×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Acosh() Function with Examples

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

math.Acosh()

The Acosh() function is an inbuilt function of the math package which is used to get the inverse hyperbolic cosine of the given value.

It accepts one parameter and returns the inverse hyperbolic cosine.

Syntax

func Acosh(x float64) float64

Parameters

  • x : The value whose inverse hyperbolic cosine value is to be found.

Return Value

The return type of Acosh() function is a float64, it returns the inverse hyperbolic cosine of the given value.

Special cases are:

  • Acosh(+Inf) = +Inf
    If the parameter is positive infinity (+Inf), it returns the same (+Inf).
  • Acosh(x) = NaN if x < 1
    If the parameter is less than 1, it returns the NaN.
  • Acosh(NaN) = NaN
    If the parameter is NaN (Not-A-Number), it returns the same (NaN).

Example 1

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

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Acosh(1))
	fmt.Println(math.Acosh(5.34))

	fmt.Println(math.Acosh(math.Inf(3)))
	fmt.Println(math.Acosh(0.5))

	fmt.Println(math.Acosh(math.NaN()))
	fmt.Println(math.Acosh(math.Sqrt(-2)))
}

Output:

0
2.3594881094303886
+Inf
NaN
NaN
NaN

Example 2

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var AcoshX float64

	x = 1
	AcoshX = math.Acosh(x)
	fmt.Println("Inverse hyperbolic cosine value of", x, "is", AcoshX)

	x = 2.5
	AcoshX = math.Acosh(x)
	fmt.Println("Inverse hyperbolic cosine value of", x, "is", AcoshX)

	x = 0.5
	AcoshX = math.Acosh(x)
	fmt.Println("Inverse hyperbolic cosine value of", x, "is", AcoshX)

	x = math.Sqrt(-2)
	AcoshX = math.Acosh(x)
	fmt.Println("Inverse hyperbolic cosine value of", x, "is", AcoshX)
}

Output:

Inverse hyperbolic cosine value of 1 is 0
Inverse hyperbolic cosine value of 2.5 is 1.566799236972411
Inverse hyperbolic cosine value of 0.5 is NaN
Inverse hyperbolic cosine value of NaN is NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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