C# Math ReciprocalEstimate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In C#, Math.ReciprocalEstimate(d) returns an estimate of the reciprocal of d, which is 1 / d. The reciprocal of 4 is 0.25, and the estimate will be close to 0.25, but not promised to be exactly 0.25.

Think of a quick mental guess versus a careful calculation. Some processors have a very fast circuit that gives the reciprocal to only about 12 bits of accuracy (roughly 3 or 4 correct digits). ReciprocalEstimate may use that circuit. It is useful in graphics and games, where speed matters and a small error is fine. The answer can be slightly different on different computers, so never compare it with ==. If you want the exact result, simply write 1.0 / d.

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

Syntax

Pass a number. The answer is an approximation of its reciprocal, as a double.

C#
double estimate = Math.ReciprocalEstimate(4);   // close to 0.25
double exact = 1.0 / 4;                          // exactly 0.25

bool close = Math.Abs(estimate - exact) < 0.01;  // true
CallWhat it does
Math.ReciprocalEstimate(4)About 0.25, but not exactly on every computer.
Math.ReciprocalEstimate(0)Returns positive Infinity.
Math.ReciprocalEstimate(double.PositiveInfinity)Returns 0.
1.0 / 4The exact way: always 0.25.

It is only an estimate. Depending on the computer, the answer may be exact or may be off by a small amount (a fraction of a percent). So always compare with a tolerance, such as Math.Abs(estimate - expected) < 0.01, and never with ==. The special cases (0, infinity, NaN) behave like normal division. The method does not throw.

Library declarations
C#
public static double ReciprocalEstimate(double d);

Parameters

ParameterDescription
dRequired. The number to estimate the reciprocal of.

Return Value

Return ValueDescription
doubleAn estimate of 1 / d. It may differ slightly from the exact value, and the difference can vary between computers. Infinity for 0, 0 for infinity, NaN for NaN.

C# Examples

Example 1 — Check an Estimate with a Tolerance

Estimate the reciprocal of three numbers and check each is close to the exact answer, without printing the raw estimate.

C#
using System;
using System.Globalization;

class Program {
    static bool Close(double a, double b) {
        return Math.Abs(a - b) < 0.01;
    }

    static void Main() {
        Console.WriteLine(Close(Math.ReciprocalEstimate(4), 0.25));
        Console.WriteLine(Close(Math.ReciprocalEstimate(10), 0.1));
        Console.WriteLine(Close(Math.ReciprocalEstimate(8), 0.125));
        Console.WriteLine(Math.Round(Math.ReciprocalEstimate(4), 2).ToString(CultureInfo.InvariantCulture));
    }
}

How It Works

  1. A tolerance helper. Close says two numbers are "the same" when they differ by less than 0.01. This is the right way to check an estimate.
  2. Three checks. The reciprocals of 4, 10, and 8 should be about 0.25, 0.1, and 0.125. Each estimate is within 0.01 of the exact value on any computer, so all three lines print True.
  3. Why not print the raw estimate? On some computers it is 0.25 exactly, and on others it is a little off, such as 0.2499. Printing it would give different output on different machines.
  4. Round to hide the error. Rounding to 2 decimals gives 0.25 everywhere. The estimate is within a fraction of a percent, so rounding hides the difference.

Example 2 — Estimate Times the Number Is About 1

Check that estimate * d is close to 1 for several numbers, and compare with the exact division.

C#
using System;

class Program {
    static void Main() {
        double[] values = { 3, 7, 50, 0.5 };
        bool allClose = true;

        foreach (double value in values) {
            double estimate = Math.ReciprocalEstimate(value);
            if (Math.Abs(estimate * value - 1) > 0.01) {
                allClose = false;
            }
        }

        Console.WriteLine(allClose);
        Console.WriteLine(1.0 / 8 == 0.125);
    }
}

How It Works

  1. A neat test. The reciprocal of d times d equals 1. So a good estimate multiplied by d should be very close to 1.
  2. Four different sizes. The values 3, 7, 50, and 0.5 range from small to large. A relative check works for all of them, unlike a fixed gap.
  3. Within 1 percent. If any estimate were more than 1 percent off, allClose would become false. The estimate is well inside that, so the result is True.
  4. The exact way. 1.0 / 8 is exactly 0.125, since 0.125 is a power of two and is stored exactly. Plain division is exact here, so the == comparison is True.

Example 3 — Zero, Infinity, NaN, and Negatives

Check the special cases with true or false answers, which do not depend on the computer.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(double.IsPositiveInfinity(Math.ReciprocalEstimate(0)));
        Console.WriteLine(Math.ReciprocalEstimate(double.PositiveInfinity) == 0);
        Console.WriteLine(double.IsNaN(Math.ReciprocalEstimate(double.NaN)));
        Console.WriteLine(Math.Abs(Math.ReciprocalEstimate(-4) + 0.25) < 0.01);
    }
}

How It Works

  1. Zero. Like 1 / 0 for a double, the estimate is positive Infinity. No exception is thrown.
  2. Infinity. The reciprocal of infinity is 0, so the estimate is 0 and the comparison is True.
  3. NaN. "Not a number" stays NaN, and double.IsNaN reports True.
  4. A negative. The reciprocal of -4 is about -0.25. Adding 0.25 should leave almost nothing, so the tolerance test prints True.

Frequently Asked Questions

It returns an estimate of 1 / d. It may use a fast hardware instruction, so the result is close to the exact reciprocal but can differ slightly, and can differ between computers.
No. It is only an estimate. Compare results with a tolerance such as Math.Abs(a - b) < 0.01, never with ==. For an exact answer use 1.0 / d.
It was added in .NET Core 3.0, so it is in modern .NET. It is not in classic .NET Framework.
Only in speed-critical code, such as graphics or physics loops, where a small error is acceptable. For everyday programs, 1.0 / d is simpler and exact.
No. Math is a static class, so you call Math.ReciprocalEstimate(...) straight on the class name. You cannot write new Math(), and there is no variable to keep.

Next: ReciprocalSqrtEstimate()

Return a quick estimate of 1 divided by the square root of a number. It is only approximate.

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

11 people found this page helpful