×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

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

Parameters

  • 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 »




Comments and Discussions!

Load comments ↻





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