What is Math.BitDecrement() in C#?

C# has a built-in Math class which provides useful mathematical functions and operations. The class has the BitDecrement() function, which is used to compute the next smallest number less than a specified number.

Syntax

public static double BitDecrement (double value);

Parameters

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

Return value

  • Double: This returns the next smallest number less than value.
  • NaN: The function returns this for NaN as an input of value.
  • NegativeInfinity: The function returns this for NegativeInfinity as an input of value.

Example

using System;
class Educative
{
static void Main()
{
Double result = Math.BitDecrement(10.1);
System.Console.WriteLine("BitDecrement(10.1) = "+ result);
Double result1 = Math.BitDecrement(Double.NaN);
System.Console.WriteLine("BitDecrement(NaN) = "+ result1);
Double result2 = Math.BitDecrement(Double.PositiveInfinity);
System.Console.WriteLine("BitDecrement(∞) = "+ result2);
}
}

Output

  • BitDecrement ( 10.1 ) = 10.099999999999998
  • BitDecrement ( NaN ) = NaN
  • BitDecrement ( -∞ ) = -∞

Free Resources