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.

Mathematical representation of the hyperbolic sine function

Note: We need to import Foundation in our code to use the sinh() function. We can import it using import 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 Swift
import Foundation
//positive number in radians
print("The value of sinh(2.3) :", sinh(2.3));
// negative number in radians
print("The value of sinh(-2.3) :", sinh(-2.3));
//converting the degrees angle into radians and then applying sinh()
// degrees = 90.0
// PI = 3.14159265
print("The value of sinh(90.0 * (PI / 180.0)) :", sinh(90.0 * (Double.pi / 180.0)));

Explanation

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

Free Resources