TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Math log1p() Function

C++ Math log1p() Function with tutorial for beginners and professionals with examples on isgreaterequal(), less(), islessequal(), islessgreater(), isunordered(), exp(), frexp(), ldexp(), log(), log10(), modf(), exp2(), expm1(), log1p(), log2(), logb(), scalbn(), scalbln() etc.

<< Back to CPP

C++ Math log1p()

The function computes the natural logarithm of a given number plus one.

Suppose a number is 'x':

log1p(x) = log(1+x);

Syntax

float log1p(float x);
double log1p(double x);
long double log1p(long double x);
double log1p(integral x);

Note: The return_type can be float, double or long double.

Parameter

x: The value of which logarithm is to be calculated.

Return value

Parameter Return value
x>0 Positive
x=0 zero
0>x> -1 Negative
x= -1 -infinity
x<-1 Not a Number(nan)

Example 1

Let's see a simple example when the value of x is greater than zero.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x=10;
     std::cout << "Value of x is : " <<x <<std::endl;
     cout<<"log1p(x) = "<<log1p(x);
     return 0;
}

Output:

Value of x is : 10
log1p(x) = 2.3979

In this example, log1p() function computes the logarithm value when x is greater than zero.

Example 2

Let's see a simple example when the value of x is zero

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x=0;
     std::cout << "Value of x is : " <<x <<std::endl;
     cout<<"log1p(x) = "<<log1p(x);
     return 0;
}

Output:

Value of x is : 0
log1p(x) = 0

In this example, log1p() function computes the logarithm value when the value of x is zero.

Example 3

Let's see a simple example when the value of x is less than zero.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= -0.5;
     std::cout << "Value of x is : " <<x <<std::endl;
     cout<<"log1p(x) = "<<log1p(x);
     return 0;
}

Output:

Value of x is : -0.5
log1p(x) = -0.693147

In this example, log1p() function computes the logarithm value when the value of x is less than zero.

Example 4

Let's see the simple example when the value of x is -1.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x= -1;
     std::cout << "Value of x is : " <<x <<std::endl;
     cout<<"log1p(x) = "<<log1p(x);
     return 0;
}

Output:

Value of x is : -1
log1p(x) = -inf

In this example, log1p() function computes the logarithm value when the value of x is -1.

Example 5

Let's see the simple example when the value of x is less than -1.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x= -3;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"log1p(x) = "<<log1p(x);
    return 0;
}

Output:

Value of x is : -3
log1p(x) = -nan

In this example, log1p() function computes the logarithm value when the value of x is less than -1.


Next TopicC++ Math Functions




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf