log10() Function with Example in C++

C++ log10() function: Here, we are going to learn about the log10() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on May 20, 2020

C++ log10() function

log10() function is a library function of cmath header, it is used to get the common logarithm (the base-10 logarithm) of the given value. It accepts a value (float, double, or long double) and returns the common logarithm.

Syntax of log10() function:

C++11:

     double log10 (double x);
      float log10 (float x);
long double log10 (long double x);
     double log10 (T x);

Parameter(s):

  • x – represents the value whose common logarithm to be found.

Return value:

It returns the common logarithm of the given value x.

Note:

  • If the given value is negative, it causes a domain error.
  • If the given value is zero, it may cause a pole error.

Example:

    Input:
    float x = 10.0f
    
    Function call:
    log(x);
    
    Output:
    1

C++ code to demonstrate the example of log10() function

// C++ code to demonstrate the example of
// log10() function

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    float x = 0.0f;

    x = 10.0f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    x = 1.0f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    x = 20.0f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    x = -10.4f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    x = 0.0f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    x = 100.6f;
    cout << "log10(" << x << "): " << log10(x) << endl;

    return 0;
}

Output

log10(10): 1
log10(1): 0
log10(20): 1.30103
log10(-10.4): nan
log10(0): -inf
log10(100.6): 2.0026

Reference: C++ log10() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.