other words: For normalized floating-point numbers, the integer part is given by the floating-point exponent, and for integers it can be determined by performing a count leading zeros operation. The fractional part of the result is and can be computed iteratively, using only elementary multiplication and division. The algorithm for computing the fractional part can be described in pseudocode as follows: Start with a real number in the half-open interval . If , then the algorithm is done, and the fractional part is zero. Otherwise, square repeatedly until the result lies in the interval . Let be the number of squarings needed. That is, with chosen such that is in . Taking the logarithm of both sides and doing some algebra: Once again is a real number in the interval . Return to step 1 and compute the binary logarithm of using the same method. The result of this is expressed by the following recursive formulas, in which is the number of squarings required in the i-th iteration of the algorithm: In the special case where the fractional part in step 1 is found to be zero, this is a finite sequence terminating at some point. Otherwise, it is an infinite series that converges according to the ratio test, since each term is strictly less than the previous one (since every ). For practical use, this infinite series must be truncated to reach an approximate result. If the series is truncated after the -th term, then the error in the result is less than . Software library support The log2 function is included in the standard C mathematical functions. The default version of this function takes double precision arguments but variants of it allow the argument to be single-precision or to be a long double. In computing environments supporting complex numbers and implicit type conversion such as MATLAB the argument to the log2 function is allowed to be a negative number, returning a complex one. References External links Feynman and the Connection Machine Binary arithmetic Calculus Logarithms