C programming sinh , sinhf and sinhl


In C programming the <math.h> sinh , sinhf and sinhl compute the hyperbolic sine of the argument.The declaration of the functions are given below.

1 float sinh(float x);
2 double sinh(double x);
3 long double sinh(long double x);
4 float sinhf(float x);
5 long double sinhl(long double x);

Parameters:
x -The value whose hyperbolic sine is to be computed.

Return type
floating point value -The hyperbolic sine of ‘x’.

All the functions are the same,they compute the hyperbolic sine of ‘x’.The 1st,2nd and the 3rd function have the same name i.e.’sinh’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note:

i) If the argument is very large Range error occur.In MINGW 6.1 and VS 2015 when x>710 ,Range error seems to occur.

ii)If NAN is passed ‘nan’ is returned.

iii)If INFINITY is passed ‘inf’ is returned.

Code example

double d=250 , x1=750 ;

float f=250 ;

long double ld=250 ;

printf(“%lf”, sinh( d ) ) ; //calls the 2nd version
printf(“\n%f”, sinh( f ) ) ; //calls the 1st version
printf(“\n%Lf”, sinh( ld ) ) ;//calls the 3rd version

printf(“\n%lf”, sinh( x1 ) ) ;
printf(“\n%lf”, sinh(NAN) ) ;

Output in Visual Studio ,

1873227307251336696773848240283601646890882105610260521756063656832967348075473365292870207808932043670159360.000000
1873227307251336696773848240283601646890882105610260521756063656832967348075473365292870207808932043670159360.000000
1873227307251336696773848240283601646890882105610260521756063656832967348075473365292870207808932043670159360.000000
inf
-nan(ind)

The ‘NAN’ macro stands for the value ‘NaN’.In the 4th output the argument passed is 750 so a range error occur hence ‘inf'(infinity) is the returned value.

Note as the argument value increases the output also increases until it reaches an infinity when the argument value is 711.

Link :C and C++ nan:myths and conception


 


sinhf

The ‘sinhf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘sinhf‘ stands for float and it signify the parameter and return type of the function.

Code example

float x= -30 ;

printf(“%f”, sinh( x ) ); //Calls the 1st version
printf(“\n%f”, sinhf( 123 ) ); Calls the 4th version

Output,

-5343237111808.000000
-5343237111808.000000


sinhl

The ‘sinhl‘ function is same as the 3rd function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘sinhl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double x= -30 ;

printf(“%Lf”, sinh( x ) ); //Calls the 3rd version
printf(“\n%Lf”, sinhl( -30 ) ); //Calls the 5th version

Output,

-5343237290762.231445
-5343237290762.231445

The difference in the accuracy of the output value of sinhl,sinh(long double) and the sinhf,sinh(long double) is a proof that the functions return different data type values.