C# Math BitIncrement() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In C#, Math.BitIncrement(x) returns the next double above x. A double cannot hold every number: between any two neighbours there is a small gap, and nothing in between. BitIncrement jumps exactly one gap up. For 1.0 the next number is 1.0000000000000002.

Think of a ruler with marks. You can only point at a mark, never between marks. BitIncrement moves your finger to the next mark on the right. The gap is not the same everywhere: near 1 it is about 0.0000000000000002, near 1,000,000 it is bigger, and near 0 it is tiny. This is an advanced tool, useful when you need "strictly greater than x" or want to explore how doubles work. Its mirror image is BitDecrement().

This is a static member of the static class System.Math. You call it with the class name, such as Math.BitIncrement(...). There is no Math object to create. All the work is done by the method you call, and it never changes your variables. Math.BitIncrement 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 greater than it.

C#
double next = Math.BitIncrement(1.0);   // 1.0000000000000002
bool bigger = next > 1.0;               // true
double up = Math.BitIncrement(0.0);     // double.Epsilon, the smallest positive double
CallWhat it does
Math.BitIncrement(1.0)Returns 1.0000000000000002.
Math.BitIncrement(0.0)Returns double.Epsilon, the smallest positive double.
Math.BitIncrement(double.MaxValue)Returns Infinity.
Math.BitIncrement(double.NaN)Returns NaN.

The result is always greater than the input, unless the input is positive infinity or NaN (which are returned as they are). Negative numbers move toward zero: BitIncrement(-1.0) is -0.9999999999999999. The size of the step depends on how big the number is. Do not use it as a general "add a little" tool.

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

Parameters

ParameterDescription
xRequired. The starting number.

Return Value

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

C# Examples

Example 1 — The Next Double Above 1.0

Call BitIncrement on 1.0, and show that adding a tiny number to 1.0 can change nothing at all.

C#
using System;

class Program {
    static void Main() {
        double next = Math.BitIncrement(1.0);

        Console.WriteLine(next);
        Console.WriteLine(next > 1.0);
        Console.WriteLine(next == 1.0);
        Console.WriteLine(1.0 + 1e-16 == 1.0);
    }
}

How It Works

  1. The next mark. The next double after 1.0 is 1.0000000000000002. There is no double between the two.
  2. Bigger. next > 1.0 is True. BitIncrement always moves up.
  3. Not the same. next == 1.0 is False. They are neighbours, but they are two different numbers.
  4. Too small to notice. Adding 0.0000000000000001 to 1.0 is less than half of the gap, so it rounds back to 1.0. That is why the last line prints True.

Example 2 — Walk Up Three Steps

Move up three steps from 1.0, check the distance with ScaleB, and show that nothing exists between neighbours.

C#
using System;

class Program {
    static void Main() {
        double x = 1.0;

        for (int i = 0; i < 3; i++) {
            x = Math.BitIncrement(x);
        }
        Console.WriteLine(x - 1.0 == Math.ScaleB(3, -52));

        double next = Math.BitIncrement(1.0);
        double middle = (1.0 + next) / 2;
        Console.WriteLine(middle == 1.0 || middle == next);

        Console.WriteLine(Math.BitIncrement(-1.0) > -1.0);
    }
}

How It Works

  1. Three steps. The loop moves up one gap at a time. Near 1.0 each gap is 2 to the power -52, so three steps add 3 x 2-52.
  2. An exact check. Math.ScaleB(3, -52) builds exactly that number, and the subtraction matches it, so the answer is True.
  3. Nothing in between. The middle of two neighbours cannot be stored, so it rounds to one of the two. The test middle == 1.0 || middle == next is True.
  4. Negative numbers. For -1.0 the next number up is -0.9999999999999999, which is closer to zero. It is greater than -1.0, so the result is True.

Example 3 — Edges: MaxValue, Zero, and NaN

See what happens at the biggest double, at negative infinity, at zero, and for NaN.

C#
using System;

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

How It Works

  1. Past the top. There is no double above double.MaxValue except infinity, so that is what you get.
  2. From negative infinity. The next number up from negative infinity is the most negative real double, double.MinValue.
  3. From zero. The next number above 0 is double.Epsilon, about 5E-324. This is the smallest positive double.
  4. NaN. "Not a number" has no next number, so it is returned unchanged. The method does not throw.

Frequently Asked Questions

It returns the next representable double above the given number: the smallest possible step up. Math.BitIncrement(1.0) is 1.0000000000000002.
It was added in .NET Core 3.0, so it is in modern .NET. It is not in classic .NET Framework.
A double stores about 15 to 17 significant digits. Near a small number those digits cover tiny steps, and near a large number they cover bigger steps. So the gap grows with the size of the number.
When you need "the smallest number strictly greater than x", for example to turn a >= limit into a > limit, or when you are testing or exploring how floating-point numbers work. For normal calculations you rarely need it.
No. Math is a static class, so you call Math.BitIncrement(...) straight on the class name. You cannot write new Math(), and there is no variable to keep.

Next: Cbrt()

Return the cube root of a number, including negative numbers.

Cbrt() 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.

8 people found this page helpful