Important: The information in this document is obsolete and should not be used for new development.
log2
You can use thelog2
function to compute the binary logarithm of a real number.
double_t log2 (double_t x);
x
- Any positive floating-point number.
DESCRIPTION
Thelog2
function returns the binary (base 2) logarithm of its argument.such that
The
exp2
function performs the inverse operation.EXCEPTIONS
When x is finite and nonzero, the result of might raise one of the following exceptions:
- inexact (for all finite, nonzero values of x other than +1)
- invalid (when x is negative)
SPECIAL CASES
Table 10-17 shows the results when the argument to thelog2
function is a zero, a NaN, or an Infinity, plus other special cases for thelog2
function.
Special cases for the log2
functionOperation Result Exceptions raised for x < 0 NaN Invalid +0 None Divide-by-zero Divide-by-zero NaN None[38] + None NaN Invalid EXAMPLES
z = log2(+1.0); /* z = +0 because 20 = 1 */ z = log2(2.0); /* z = 1 because 21 = 2. The inexact exception is raised. */ z = log2(-1.0); /* z = NAN because negative arguments are not allowed. The invalid exception is raised. */
[38] If the NaN is a signaling NaN, the invalid exception is raised.