The tanh()
function in Swift returns a number’s hyperbolic tangent.
Below is the mathematical representation of the tanh()
function:
Note: We need to import
Foundation
in our code to use thetanh()
function. We can import it like this:import Foundation
.
tanh(num)
This function requires a number
representing an angle
in radians
as a parameter.
To convert degrees
to radians
, use:
radians = degrees * ( pi / 180.0 )
This function returns the hyperbolic tangent of a number sent as a parameter.
The code below shows the use of the tanh()
function in Swift:
import Swiftimport Foundation//positive number in radiansprint("The value of tanh(2.3) :", tanh(2.3));// negative number in radiansprint("The value of tanh(-2.3) :", tanh(-2.3));//converting the degrees angle into radians and then applying tanh()// degrees = 45.0// PI = 3.14159265print("The value of tanh(45.0 * (PI / 180.0)) :", tanh(45.0 * (Double.pi / 180.0)));
Foundation
header required for tanh()
function.tanh()
.tanh()
.tanh()
.