Trusted answers to developer questions

What is Math.ILogB() in C#?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

C# has a built-in Math class that provides useful mathematical functions and operations. This class has the ILogB() function, which is used to compute the base 2 integer logarithm of a specified number.

Syntax

public static int ILogB (double value);

Parameters

  • value: This is of the Double type and represents the input value for which we have to find ILogB(). Its range is all double numbers.

Return value

  • Double: This returns a positive Double number representing the base 2 integer log of the value.
  • MinValue: This returns an input of 0 in value.
  • MaxValue: This returns an input of NaN, NegativeInfinity, and PositiveInfinity in value.

MinValue is the smallest possible Int32 value, equal to -2147483648. MaxValue is the largest possible Int32 value, equal to 2147483647.

Example

using System;
class Educative
{
static void Main()
{
double result = Math.ILogB(10);
System.Console.WriteLine("ILogB(10) = "+ result);
double result1 = Math.ILogB(0);
System.Console.WriteLine("ILogB(0) = "+ result1);
double result2 = Math.ILogB(Double.PositiveInfinity);
System.Console.WriteLine("ILogB(∞) = "+ result2);
}
}

Output

ILogB(10) = 3
ILogB(0) = -2147483648
ILogB(∞) = 2147483647

RELATED TAGS

c#
ilogb
math
Did you find this helpful?