名前空間
変種
操作

std::log10, std::log10f, std::log10l

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
 
ヘッダー <cmath> で定義
(1)
float       log10 ( float num );

double      log10 ( double num );

long double log10 ( long double num );
(C++23まで)
/*浮動小数点数型*/
            log10 ( /*浮動小数点型*/ num );
(C++23から)
(C++26 以降 constexpr)
float       log10f( float num );
(2) (C++11以降)
(C++26 以降 constexpr)
long double log10l( long double num );
(3) (C++11以降)
(C++26 以降 constexpr)
ヘッダー <simd> で定義
template< /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/<V>

            log10 ( const V& v_num );
(S) (C++26以降)
ヘッダー <cmath> で定義
template< class Integer >
double      log10 ( Integer num );
(A) (C++26 以降 constexpr)
1-3) num常用対数(底が10の対数)を計算します。ライブラリは、パラメータの型として、すべての cv 修飾されていない浮動小数点型に対する std::log10 のオーバーロードを提供します。(since C++23)
S) SIMD オーバーロードは、v_num に対して要素ごとの std::log10 を実行します。
(定義については、math-floating-point および deduced-simd-t を参照してください。)
(C++26以降)
A) すべての整数型に対する追加のオーバーロードが提供されます。これらは double として扱われます。
(C++11以降)

目次

[編集] Parameters

num - 浮動小数点数または整数値

[編集] Return value

エラーが発生しなかった場合、num の常用対数(log10(num) または lg(num))が返されます。

領域エラーが発生した場合、実装定義の値が返される (サポートされている場合はNaN)。

If a pole error occurs, -HUGE_VAL, -HUGE_VALF, or -HUGE_VALL is returned.

[編集] Error handling

エラーは math_errhandling で指定された通りに報告される。

Domain error occurs if num is less than zero.

Pole error may occur if num is zero.

実装がIEEE浮動小数点算術 (IEC 60559) をサポートしている場合、

  • If the argument is ±0, -∞ is returned and FE_DIVBYZERO is raised.
  • If the argument is 1, +0 is returned.
  • If the argument is negative, NaN is returned and FE_INVALID is raised.
  • 引数が +∞ の場合、+∞ が返されます。
  • 引数が NaN の場合、NaN が返されます。

[編集] Notes

追加のオーバーロードは、(A) とまったく同じように提供される必要はありません。整数型の引数 num に対して、std::log10(num)std::log10(static_cast<double>(num)) と同じ効果を持つことを保証するだけで十分です。

[編集] Example

#include <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
 
int main()
{
    std::cout << "log10(1000) = " << std::log10(1000) << '\n'
              << "log10(0.001) = " << std::log10(0.001) << '\n'
              << "base-5 logarithm of 125 = "
              << std::log10(125) / std::log10(5) << '\n';
 
    // special values
    std::cout << "log10(1) = " << std::log10(1) << '\n'
              << "log10(+Inf) = " << std::log10(INFINITY) << '\n';
 
    // error handling
    errno = 0;
    std::feclearexcept(FE_ALL_EXCEPT);
 
    std::cout << "log10(0) = " << std::log10(0) << '\n';
 
    if (errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if (std::fetestexcept(FE_DIVBYZERO))
        std::cout << "    FE_DIVBYZERO raised\n";
}

実行結果の例

log10(1000) = 3
log10(0.001) = -3
base-5 logarithm of 125 = 3
log10(1) = 0
log10(+Inf) = inf
log10(0) = -inf
    errno == ERANGE: Numerical result out of range
    FE_DIVBYZERO raised

[編集] See also

(C++11)(C++11)
自然対数 (e を底とする) を計算する (ln(x))
(関数) [編集]
(C++11)(C++11)(C++11)
与えられた数値の 2 を底とする対数 (log2(x))
(関数) [編集]
(C++11)(C++11)(C++11)
与えられた数値に 1 を足した値の自然対数 (e を底とする) (ln(1+x))
(関数) [編集]
複素数の常用対数、分枝切断は負の実軸に沿う
(関数テンプレート) [編集]
valarray の各要素に std::log10 関数を適用します。
(function template) [編集]
C documentation for log10
English 日本語 中文(简体) 中文(繁體)