Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
ilogb
math
communitycreator

What is Math.ILogB() in C#?

Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring