What is sinh() in D?

The sinh() function in D calculates and 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 std.math in our code to use the sinh() function. We can import it like this:
import std.math

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 (radians), which is sent as a parameter.

Example

The code below shows how to use the sinh() function in D:

import core.stdc.stdio;
import std.stdio;
//Header required for the function
import std.math;
int main()
{
//Positive number in radians
writeln("The value of sinh(2.3) :", sinh(2.3));
// Negative number in radians
writeln("The value of sinh(-2.3) :", sinh(-2.3));
//Convert the degrees angle into radians and then apply sinh()
// degrees = 90.0
// PI = 3.14159265
// The result first converts the degrees angle into radians and then applies sinh()
double result=sinh(90.0 * (PI / 180.0));
writeln("The value of sinh(90.0 * (PI / 180.0)) ", result);
//Exceptional output
writeln ("The value of sinh(real.infinity) : ",sinh(real.infinity));
writeln ("The value of sinh(-real.infinity) : ",sinh(-real.infinity));
writeln ("The value of sinh(real.nan) : ",sinh(real.nan));
writeln ("The value of sinh(-real.nan) : ",sinh(-real.nan));
return 0;
}

Explanation

  • Line 4: We add the std.math header required for the sinh() function.

  • Line 9: We calculate the hyperbolic sine of a positive number in radians using sinh().

  • Line 12: We calculate the hyperbolic sine of a negative number in radians using sinh().

  • Lines 18 to 19: The variable result first converts degrees to radians, and then applies sinh().

  • Line 21 onwards: We calculate the hyperbolic sine of exceptional numbers using sinh().