What is the atanh() function in Swift?
Overview
The atanh() function, returns the inverse hyperbolic tangent of a number.
Figure 1 shows the mathematical representation of the atanh() function.
Note: We import
Foundationin our code to useatanh()by usingimport Foundation.
Syntax
The syntax of the function is as follows:
atanh(number)
//number can be real, float, or double.
Parameter
This function requires a number as a parameter.
Note: The parameter should be between -1 and 1.
Return value
atanh() returns the inverse hyperbolic tangent of a number that is sent as a parameter.
Example
The code below shows the use of the atanh() function in swift.
import Swiftimport Foundation//positive numberprint("The value of atanh(0.5) :", atanh(0.5));// negative numberprint("The value of atanh(-0.5) :", atanh(-0.5));//-1print("The value of atanh(-1.0): ",atanh(-1.0) );//1print("The value of atanh(1.0): ",atanh(1.0) );// >1print("The value of atanh(2.0): ",atanh(2.0) );// <-1print("The value of atanh(-2.0): ",atanh(-2.0) );
Explanation
- Line 2: We add the
Foundationheader required foratanh()function. - Line 5: We use
atanh()to calculate the inverse hyperbolic tangent of the positive number (-1< number <1).
- Line 8: We use
atanh()to calculate the inverse hyperbolic tangent of the negative number (-1< number <1).
- Line 11: We use
atanh()to calculate the inverse hyperbolic tangent of -1.
- Line 14: We use
atanh()to calculate the inverse hyperbolic tangent of 1.
- Line 17: We use
atanh()to calculate the inverse hyperbolic tangent of number>1.
- Line 20: We use
atanh()to inverse the hyperbolic tangent of number <-1.