C# Tutorial C# Advanced C# References

C# Math - BitDecrement() Method



The C# BitDecrement() method returns the next smallest value that compares less than the argument. In special cases it returns the following:

  • If the argument is NaN, the method returns NaN.
  • If the argument is negative infinity, the method returns negative infinity.

Syntax

public static double BitDecrement (double arg);

Parameters

arg Specify the value to decrement.

Return Value

Returns the next smallest value that compares less than the argument.

Example:

In the example below, BitDecrement() method returns the next smallest value that compares less than the argument.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine("Math.BitDecrement(2) = "
                      + Math.BitDecrement(2));
    Console.WriteLine("Math.BitDecrement(10.1) = "
                      + Math.BitDecrement(10.1));
    Console.WriteLine("Math.BitDecrement(32.23) = "
                      + Math.BitDecrement(32.23));                      
    Console.WriteLine("Math.BitDecrement(0) = "
                      + Math.BitDecrement(0));
    Console.WriteLine("Math.BitDecrement(-10.1) = "
                      + Math.BitDecrement(-10.1));
    Console.WriteLine("Math.BitDecrement(Double.NaN) = "
                      + Math.BitDecrement(Double.NaN));
    Console.WriteLine("Math.BitDecrement(Double.NegativeInfinity) = "
                      + Math.BitDecrement(Double.NegativeInfinity));
    Console.WriteLine("Math.BitDecrement(Double.PositiveInfinity) = "
                      + Math.BitDecrement(Double.PositiveInfinity));
  }
}

The output of the above code will be:

Math.BitDecrement(2) = 1.9999999999999998
Math.BitDecrement(10.1) = 10.099999999999998
Math.BitDecrement(32.23) = 32.22999999999999
Math.BitDecrement(0) = -5E-324
Math.BitDecrement(-10.1) = -10.100000000000001
Math.BitDecrement(Double.NaN) = NaN
Math.BitDecrement(Double.NegativeInfinity) = -Infinity
Math.BitDecrement(Double.PositiveInfinity) = 1.7976931348623157E+308

❮ C# Math Methods

5