std::log, std::logf, std::logl
提供: cppreference.com
ヘッダ <cmath> で定義 | ||
(1) | ||
float log (float arg ); | ||
float logf(float arg ); | (C++11以上) | |
double log (double arg ); | (2) | |
(3) | ||
longdouble log (longdouble arg ); | ||
longdouble logl(longdouble arg ); | (C++11以上) | |
double log ( 整数型 arg ); | (4) | (C++11以上) |
1-3)
arg
の (e を底とする) 自然対数を計算します。目次 |
[編集]引数
arg | - | 浮動小数点または整数型の値 |
[編集]戻り値
エラーが発生しなければ、 arg
の (e を底とする) 自然対数 (ln(arg) または log
e(arg)) が返されます。
定義域エラーが発生した場合、処理系定義の値 (サポートされていれば NaN) が返されます。
極エラーが発生した場合、 -HUGE_VAL
、 -HUGE_VALF
または -HUGE_VALL
が返されます。
[編集]エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
arg
がゼロより小さい場合、定義域エラーが発生します。
arg
がゼロの場合、極エラーが発生するかもしれません。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 -∞ が返され、 FE_DIVBYZERO が発生します。
- 引数が 1 であれば、 +0 が返されます。
- 引数が負であれば、 NaN が返され、 FE_INVALID が発生します。
- 引数が +∞ であれば、 +∞ が返されます。
- 引数が NaN であれば、 NaN が返されます。
[編集]例
Run this code
#include <iostream>#include <cmath>#include <cerrno>#include <cstring>#include <cfenv>#pragma STDC FENV_ACCESS ONint main(){std::cout<<"log(1) = "<< std::log(1)<<'\n'<<"base-5 logarithm of 125 = "<< std::log(125)/std::log(5)<<'\n';// 特殊な値std::cout<<"log(1) = "<< std::log(1)<<'\n'<<"log(+Inf) = "<< std::log(INFINITY)<<'\n';// エラー処理errno=0;std::feclearexcept(FE_ALL_EXCEPT);std::cout<<"log(0) = "<< std::log(0)<<'\n';if(errno==ERANGE)std::cout<<" errno == ERANGE: "<<std::strerror(errno)<<'\n';if(std::fetestexcept(FE_DIVBYZERO))std::cout<<" FE_DIVBYZERO raised\n";}
出力例:
log(1) = 0 base-5 logarithm of 125 = 3 log(1) = 0 log(+Inf) = inf log(0) = -inf errno == ERANGE: Numerical result out of range FE_DIVBYZERO raised
[編集]関連項目
(C++11)(C++11) | 常用対数 (log10(x)) を計算します (関数) |
(C++11)(C++11)(C++11) | 指定された値の2を底とする対数 (log2(x)) を計算します (関数) |
(C++11)(C++11)(C++11) | 指定された値に1を加えた値の自然対数 (ln(1+x)) を計算します (関数) |
(C++11)(C++11) | e の x 乗 (ex) を計算します (関数) |
負の実軸に沿って分岐切断する複素自然対数 (関数テンプレート) | |
valarray の各要素に関数 std::log を適用します (関数テンプレート) | |
log の C言語リファレンス |