C# Math BitDecrement() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In C#, Math.BitDecrement(x) returns the next double below x. It moves one gap down on the double "ruler", where gaps are the smallest steps a double can take. For 1.0 the next number down is 0.9999999999999999.

The most useful trick is to find the largest number that is still smaller than a limit. If a value must be "less than 1" (not "less than or equal"), then Math.BitDecrement(1.0) is as close to 1 as you may go. Random-number code and range checks sometimes need exactly this. It is the mirror image of BitIncrement(), and it is an advanced tool for beginners to know about rather than use daily.

This is a static member of the static class System.Math. You call it with the class name, such as Math.BitDecrement(...). There is no Math object to create. All the work is done by the method you call, and it never changes your variables. Math.BitDecrement was added in .NET Core 3.0. It is not in classic .NET Framework.

Syntax

Pass a double. You get the next double that is smaller than it.

C#
double below = Math.BitDecrement(1.0);   // 0.9999999999999999
bool smaller = below < 1.0;              // true
double down = Math.BitDecrement(0.0);    // -double.Epsilon
CallWhat it does
Math.BitDecrement(1.0)Returns 0.9999999999999999.
Math.BitDecrement(0.0)Returns -double.Epsilon, the tiniest negative double.
Math.BitDecrement(double.MinValue)Returns -Infinity.
Math.BitDecrement(double.NaN)Returns NaN.

The result is always smaller than the input, unless the input is negative infinity or NaN (returned as they are). For positive numbers it moves toward zero, and for negative numbers it moves away from zero. BitDecrement(BitIncrement(x)) brings you back to x. The step size depends on how large the number is.

Library declarations
C#
public static double BitDecrement(double x);

Parameters

ParameterDescription
xRequired. The starting number.

Return Value

Return ValueDescription
doubleThe largest double that is smaller than x. -Infinity for double.MinValue, double.MaxValue for positive infinity, and NaN or negative infinity unchanged.

C# Examples

Example 1 — The Next Double Below 1.0

Call BitDecrement on 1.0 and check that it undoes BitIncrement.

C#
using System;

class Program {
    static void Main() {
        double below = Math.BitDecrement(1.0);

        Console.WriteLine(below);
        Console.WriteLine(below < 1.0);
        Console.WriteLine(Math.BitDecrement(Math.BitIncrement(1.0)) == 1.0);
    }
}

How It Works

  1. The next mark down. The closest double below 1.0 is 0.9999999999999999. Nothing can be stored between it and 1.0.
  2. Smaller. below < 1.0 is True. The step always goes down.
  3. A round trip. BitIncrement(1.0) goes one step up and BitDecrement goes one step back down. You are at 1.0 again, so the result is True.
  4. Gap below versus above. The step below 1.0 is half the size of the step above 1.0, because the stored exponent changes at 1.0.

Example 2 — The Largest Number Below a Limit

Use BitDecrement to find the largest double that is strictly below 1 and below 10.

C#
using System;

class Program {
    static void Main() {
        double almostOne = Math.BitDecrement(1.0);
        Console.WriteLine(Math.Floor(almostOne));
        Console.WriteLine(Math.Floor(1.0));

        double below10 = Math.BitDecrement(10.0);
        Console.WriteLine(below10 < 10.0);
        Console.WriteLine(below10 == 10.0);
    }
}

How It Works

  1. Just under 1. almostOne is the biggest double that is still below 1. It is so close that you might think it is 1.
  2. Floor tells the truth. Math.Floor(almostOne) is 0, because the number really is below 1. Math.Floor(1.0) is 1.
  3. Just under 10. below10 is the neighbour of 10 on the lower side. It is smaller, so below10 < 10.0 is True.
  4. Not equal. Even though the two are one step apart, below10 == 10.0 is False. This is how a "less than 10, never 10" limit can be built.

Example 3 — Edges: Zero, MinValue, Infinity, and NaN

See what happens at zero, at the lowest double, at positive infinity, and for NaN.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Math.BitDecrement(0.0) == -double.Epsilon);
        Console.WriteLine(Math.BitDecrement(double.MinValue));
        Console.WriteLine(Math.BitDecrement(double.PositiveInfinity) == double.MaxValue);
        Console.WriteLine(Math.BitDecrement(double.NaN));
    }
}

How It Works

  1. Below zero. The next number down from 0 is -double.Epsilon, the tiniest negative double. The comparison prints True.
  2. Past the bottom. There is no double below double.MinValue except negative infinity, so you get -Infinity.
  3. From infinity. The next number down from positive infinity is the biggest real double, double.MaxValue.
  4. NaN. "Not a number" has no neighbour, so it is returned unchanged. The method does not throw.

Frequently Asked Questions

It returns the next representable double below the given number, the smallest possible step down. Math.BitDecrement(1.0) is 0.9999999999999999.
Use Math.BitDecrement(1.0). It gives 0.9999999999999999, which is strictly less than 1.
It was added in .NET Core 3.0, so it is in modern .NET. It is not in classic .NET Framework.
BitDecrement always moves exactly one step down. Subtracting a small number may do nothing (if it is smaller than half the gap) or move several steps, depending on the size of the starting number.
No. Math is a static class, so you call Math.BitDecrement(...) straight on the class name. You cannot write new Math(), and there is no variable to keep.

Next: BitIncrement()

Return the very next double above a number: the smallest step up that a double can show.

BitIncrement() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful