C ++中的log10()函數(shù)返回參數(shù)的公共對(duì)數(shù)(以10為底的對(duì)數(shù))。
此函數(shù)在<cmath>頭文件中定義。
log10x = log10(x)
double log10 (double x); float log10 (float x); long double log10 (long double x); double log10 (T x); //為整型
log10()函數(shù)采用范圍為[0,∞]的單個(gè)必需參數(shù)。
如果該值小于0,則log10()返回NaN(非數(shù)字)。
log10()函數(shù)返回?cái)?shù)字的以10為底的對(duì)數(shù)。
| 參數(shù)(x) | 返回VALUE |
|---|---|
| x> 1 | Positive |
| x = 1 | 0 |
| 0> x> 1 | Negative |
| x = 0 | -∞(-無(wú)窮大) |
| x <0 | nan (不是數(shù)字) |
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double x = 13.056, result;
result = log10(x);
cout << "log10(x) = " << result << endl;
x = -3.591;
result = log10(x);
cout << "log10(x) = " << result << endl;
return 0;
}運(yùn)行該程序時(shí),輸出為:
log10(x) = 1.11581 log10(x) = nan
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int x = 2;
double result;
result = log10(x);
cout << "log10(x) = " << result << endl;
return 0;
}運(yùn)行該程序時(shí),輸出為:
log10(x) = 0.30103