What is the sinh() function in Swift?
Overview
The sinh() function in Swift returns the hyperbolic sine of a number.
The illustration below shows the mathematical representation of the sinh() function.
Note: We need to import
Foundationin our code to use thesinh()function. We can import it usingimport Foundation.
Syntax
sinh(num)
Parameter
This function requires a number that represents an angle in radians as a parameter.
The following formula converts degrees to radians.
radians = degrees * ( pi / 180.0 )
Return value
sinh() returns a number’s hyperbolic sine, which is sent as a parameter.
Example
The code below shows us how to use the sinh() function in Swift:
import Swiftimport Foundation//positive number in radiansprint("The value of sinh(2.3) :", sinh(2.3));// negative number in radiansprint("The value of sinh(-2.3) :", sinh(-2.3));//converting the degrees angle into radians and then applying sinh()// degrees = 90.0// PI = 3.14159265print("The value of sinh(90.0 * (PI / 180.0)) :", sinh(90.0 * (Double.pi / 180.0)));
Explanation
- Line 2: We add the
Foundationheader required forsinh()function. - Line 5: We calculate the hyperbolic sine of the positive number in radians using
sinh(). - Line 8: We calculate the hyperbolic sine of the negative number in radians using
sinh().
- Line 13: We convert the angle in degrees to radians and then calculate its hyperbolic sine using
sinh().