Home »
Python
math.atanh() method with example in Python
Python math.atanh() method: Here, we are going to learn about the math.atanh() method with example in Python.
Submitted by IncludeHelp, on April 25, 2019
Python math.atanh() method
math.atanh() method is a library method of math module, it is used to get the hyperbolic arc tangent of given number in radians, it accepts a number and returns hyperbolic arc tangent.
Note: math.atanh() method accepts only numbers, if we provide any number which is not in the range it returns a ValueError – "ValueError: math domain error", if we provide anything else except the number, it returns error TypeError – "TypeError: a float is required".
Syntax of math.atanh() method:
math.atanh(x)
Parameter(s): x – is the number whose hyperbolic arc tangent to be calculated.
Return value: float – it returns a float value that is the hyperbolic arc tangent value of the number x.
Example:
Input:
x = .99
# function call
print(math.atanh(x))
Output:
2.6466524123622457
Python code to demonstrate example of math.atanh() method
# Python code to demonstrate example of
# math.atanh() method
# importing math module
import math
# number
x = -0.23
print("math.atanh(",x,"): ", math.atanh(x))
x = 0
print("math.atanh(",x,"): ", math.atanh(x))
x = .99
print("math.atanh(",x,"): ", math.atanh(x))
Output
math.atanh( -0.23 ): -0.2341894667593668
math.atanh( 0 ): 0.0
math.atanh( 0.99 ): 2.6466524123622457
ValueError example
# Python code to demonstrate example of
# math.atanh() method with exception
# importing math module
import math
# number
x = -1
print("math.atanh(",x,"): ", math.atanh(x))
Output
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("math.atanh(",x,"): ", math.atanh(x))
ValueError: math domain error
TypeError example
# Python code to demonstrate example of
# math.atanh() method with exception
# importing math module
import math
# number
x = "2"
print("math.atanh(",x,"): ", math.atanh(x))
Output
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("math.atanh(",x,"): ", math.atanh(x))
TypeError: a float is required