C# has a built-in Math
class which provides useful mathematical functions and operations. The class has the Log2()
function, which is used to compute the base 2 logarithm of a specified number.
public static double Log2 (double value);
Double
type and represents the input value for which we have to find Log2()
. value
is a base 10 number with all double numbers.Double: The function returns a positive Double
number representing the base 2 log of the value
.
NaN: The function returns this for a negative or NaN
input in value
.
PositiveInfinity: The function returns this for PositiveInfinity
as input in value
.
NegativeInfinity: The function returns this for 0 as input in value
.
using System;class Educative{static void Main(){double result = Math.Log2(8);System.Console.WriteLine("Log2(8) = "+ result);double result1 = Math.Log2(Double.PositiveInfinity));System.Console.WriteLine("Log2(∞) = "+ result1);double result2 = Math.Log2(0);System.Console.WriteLine("Log2(0) = "+ result2);}}