C++ Math log2()The function computes the base 2 logarithm of a given number. Suppose a number is 'x':SyntaxNote: The return_type can be float, double or long double.Parameterx: The value whose logarithm is to be calculated. Return value
Example 1Let's see the simple example when the value of x is greater than one. Output: Value of x is : 2 log2(x) = 1 In this example, log2() function computes the logarithm value of base 2 when the value of x is greater than one Example 2Let's see the simple example when the value of x is equal to 1. Output: Value of x is : 1 log2(x) = 0 In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to one. Example 3Let's see the simple example when the value of x lies between 0 and 1. Output: Value of x is : 0.2 log2(x) = -2.32193 In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to 0.2. Example 4Let's see the simple example when the value of x is equal to zero. Output: Value of x is : 0 log2(x) = -inf In this example, log2() function computes the logarithm value of base 2 when the value of x is equal to 0. Example 5Let's see the simple example when the value of x is less than zero. Output: Value of x is : -1.5 log2(x) = nan In this example, log2() function computes the logarithm value of base 2 when the value of x is less than zero. Next TopicC++ Math Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India