標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <math.h>
double log(double x);
float log(float x); /* C++ only */
long double log(long double x); /* C++ only */
float logf(float x);
long double logl(long double x);
計算値を戻します。
x が負の場合、関数は errno を EDOM に設定し、-HUGE_VAL を戻します。x が 0.0 の場合、関数は -HUGE_VAL を戻し、errno に ERANGE を設定します。正しい値がアンダーフローの原因になった場合には、0 が戻され、ERANGE の値が errno に保管されます。
IEEE の特殊な動作: x が 0 より大きい場合、関数は x の自然対数 (基数 e) を戻します。
⁄* CELEBL08
This example calculates the natural logarithm of 1000.0.
*⁄
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 1000.0, y;
y = log(x);
printf("The natural logarithm of %lf is %lf¥n", x, y);
}
The natural logarithm of 1000.000000 is 6.907755