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.

Figure 1: Mathematical representation of inverse hyperbolic tangent function

Note: We import Foundation in our code to use atanh()by using import 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 Swift
import Foundation
//positive number
print("The value of atanh(0.5) :", atanh(0.5));
// negative number
print("The value of atanh(-0.5) :", atanh(-0.5));
//-1
print("The value of atanh(-1.0): ",atanh(-1.0) );
//1
print("The value of atanh(1.0): ",atanh(1.0) );
// >1
print("The value of atanh(2.0): ",atanh(2.0) );
// <-1
print("The value of atanh(-2.0): ",atanh(-2.0) );

Explanation

  • Line 2: We add the Foundation header required for atanh() 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.

      Free Resources