The cosh()
function returns the hyperbolic cosine of a number.
The figure below shows the mathematical representation of the cosh()
function:
Note: Import
std.math
in the code to use thecosh()
function. We can import it like this:import std.math
cosh(num)
This function requires a number that represents an angle in radians as a parameter.
To convert degrees to radians, use the following formula:
radians = degrees * ( pi / 180.0 )
cosh()
returns the hyperbolic cosine of a number sent as a parameter.
The code below shows how to use the cosh()
function in D:
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//positive number in radianswriteln("The value of cosh(2.3): ", cosh(2.3));// negative number in radianswriteln("The value of cosh(-2.3): ", cosh(-2.3));//converting the degrees angle into radians and then applying cosh()// degrees = 180.0// PI = 3.14159265// result first converts degrees to radians then apply coshdouble result=cosh(180.0 * (PI / 180.0));writeln("The value of cosh(180.0 * (PI / 180.0)): ", result);//exceptional outputwriteln ("The value of cosh(real.infinity) : ",cosh(real.infinity));writeln ("The value of cosh(-real.infinity) : ",cosh(-real.infinity));writeln ("The value of cosh(real.nan) : ",cosh(real.nan));writeln ("The value of cosh(-real.nan) : ",cosh(-real.nan));return 0;}
Line 4: We add the header std.math
required for the cosh()
function.
Line 9: We calculate hyperbolic cosine of a positive angle given in radians using cosh()
.
Line 12: We calculate hyperbolic cosine of a negative angle given in radians using cosh()
.
Line 18: We convert the degrees into radians and then apply the cosh()
function. The variable result
first converts degrees into radians and then applies cosh()
.
Lines 22 to 26: We calculate the hyperbolic cosine of exceptional numbers using cosh()
.