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.
Note: We need to import
std.mathin our code to use thesinh()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 functionimport std.math;int main(){//Positive number in radianswriteln("The value of sinh(2.3) :", sinh(2.3));// Negative number in radianswriteln("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 outputwriteln ("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.mathheader required for thesinh()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
resultfirst converts degrees to radians, and then appliessinh(). -
Line 21 onwards: We calculate the hyperbolic sine of exceptional numbers using
sinh().