ADVERTISEMENT
ADVERTISEMENT

Golang math.Atanh() Function with Examples

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

math.Atanh()

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

It accepts one parameter and returns the inverse hyperbolic tangent.

Syntax:

func Atanh(x float64) float64

Parameter(s):

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

Return Value:

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

Special cases are:

  • Atanh(1) = +Inf
    If the parameter is 1, it returns +Inf.
  • Atanh(±0) = ±0
    If the parameter is ±0, it returns the same (±0).
  • Atanh(-1) = -Inf
    If the parameter is -1, it returns the -Inf.
  • Atanh(x) = NaN if x < -1 or x > 1
    If the parameter is either less than -1 or greater than 1, it returns the NaN (Not-A-Number).
  • Atanh(NaN) = NaN
    If the parameter is NaN, it returns the same (NaN).

Example 1:

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

package main

import (
	"fmt"
	"math"
)

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

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

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

	fmt.Println(math.Atanh(-0))
	fmt.Println(math.Atanh(0))

	fmt.Println(math.Atanh(math.Inf(-1)))
	fmt.Println(math.Atanh(math.Inf(1)))
}

Output:

+Inf
0.2341894667593668
-Inf
-0.2341894667593668
NaN
NaN
0
0
NaN
NaN

Example 2:

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var AtanhX float64

	x = 0
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = 0.23
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = 1
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = -0.23
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = -2
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = 10
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = math.Inf(-1)
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)

	x = math.Inf(1)
	AtanhX = math.Atanh(x)
	fmt.Println("Inverse hyperbolic tangent value of", x, "is", AtanhX)
}

Output:

Inverse hyperbolic tangent value of 0 is 0
Inverse hyperbolic tangent value of 0.23 is 0.2341894667593668
Inverse hyperbolic tangent value of 1 is +Inf
Inverse hyperbolic tangent value of -0.23 is -0.2341894667593668
Inverse hyperbolic tangent value of -2 is NaN
Inverse hyperbolic tangent value of 10 is NaN
Inverse hyperbolic tangent value of -Inf is NaN
Inverse hyperbolic tangent value of +Inf is NaN

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.