# C programming log1p,log1pf and log1pl math.h

In C programming the <math.h> log1p,log1pf and log1pl function compute the base-e logarithm of 1 plus the argument value.The declaration of the functions are given below.

1 float log1p(float x);
2 double log1p(double x);
3 long double log1p(long double x);
4 float log1pf(float x);
5 long double log1pl(long double x);

Parameters:
x – The value whose logarithm is to be computed.

Return type
floating point -The base-e logarithm of ‘x+1’.

All the functions are the same,they compute the base-e logarithm of 1 plus the argument value.The 1st,2nd and the 3rd function have the same name i.e.’log1p’.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) log1p(x) is same as loge(x+1).

ii) Domain error occur if the passed value is less than -1.

iii) Range error occur if the argument equals -1.

iv) If ‘NAN’ is passed ‘nan’ is returned,if INFINITY is passed ‘infinity’ is returned.

Code example

double d=50 , x1=-2 ;

float f=50 ;

long double ld=50 ;

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

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

Output in Visual Studio,

3.931826
3.931826
3.931826
nan
-nan(ind)

When -2 is passed as the argument ‘nan'(NaN) is returned which is a sign that domain error has occurred.

#### log1pf

The ‘log1pf‘ 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 ‘log1pf‘ stands for float and it signify the parameter and return type of the function.

Code example

float x=10 ;

printf(“%f”, log1p( x ) ); //Calls the 1st version
printf(“\n%f”, log1pf( 10 ) ); Calls the 4th version

Output in Visual Studio,

2.397895
2.397895

#### log1pl

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

Code example

long double x=10 ;

printf(“%Lf”, log1p( x ) ); //Calls the 3rd version
printf(“\n%Lf”, log1pl( 10 ) ); Calls the 5th version

Output,

2.397895
2.397895