The guide
Gamma and erf are easy to quote and easy to get wrong, so a calculator should measure its own error
Why the gamma function has poles, how the reflection formula reaches the negative axis, why erfc needs its own routine, and how a measured error differs from a guaranteed one.
- -3.5449077 Gamma(-0.5): negative, and the sign must be kept
- 2.1519737e-17 erfc(6), where 1 - erf(6) comes out as exactly 0
- 7.2574156e306 Gamma(171), the last whole-number value that fits a double
- 1.959964 two-sided 95 percent normal quantile from the inverse erf
- 9.25e-14 worst measured relative error of Gamma on this page's grid
Read the full guide Fold the guide
A calculator that prints sixteen digits invites trust. For the gamma and error functions that trust is easy to misplace, because two ordinary shortcuts quietly destroy an answer: dropping a sign, and subtracting two numbers that are almost equal.
The page evaluates a small family from a few typed numbers. It returns Gamma, its logarithm, Beta, the error function erf, its complement erfc, and the inverse of erf. Each is a smooth curve that is easy to describe and awkward to compute across its whole range. A value quoted from memory is usually fine in the middle and wrong at the edges: at a negative argument, at x = 172, or out in the tail of erf at x = 6.
What the gamma function extends
The gamma function carries the factorial off the whole numbers. For a positive whole number n, Gamma(n) equals (n - 1)!, so Gamma(5) is 24. Between the whole numbers it fills in a smooth curve, and the best-known landing is Gamma(1/2), which is the square root of pi, about 1.7724538509.
The Beta function is built from it. Beta(x, y) equals Gamma(x) times Gamma(y), divided by Gamma(x + y), which is why a Beta routine is only as good as the gamma routine under it. Beta(2, 3) is exactly 1/12, a handy test, because the three gamma values involved are all whole-number factorials.
Factorials grow fast, and a double cannot follow them forever. The largest double is about 1.7976931348623157e308. Gamma(171) is 170!, which is 7.2574156e306 and fits. Gamma(172) is 171!, which does not. The last point that fits is near x = 171.6244. Past it the page says so in words and gives the logarithm instead, since the natural logarithm of Gamma(172) is only about 711.7147 and is perfectly easy to hold. (The page writes that logarithm as log, and always means base e.)
Why the poles sit where they do
The gamma function obeys Gamma(z + 1) = z Gamma(z). Rearranged, it says Gamma(z) = Gamma(z + 1) / z. At z = 0 that asks for a division by zero, and the same step repeats one place to the left, then another, so the trouble recurs at 0, -1, -2 and on down.
These are simple poles. The reference handbook of the National Institute of Standards and Technology gives the residue at z = -n as (-1)^n / n!, and notes that the reciprocal 1 / Gamma is a well-behaved function with simple zeros at those same places.
So the page returns no number at x = -3. It says the value is not defined and that the function has a pole there. Close to a pole the size grows without limit, which is why even a tiny positive x such as 1e-310 overflows a double. The input is small and the output is not.
The negative axis, and the reflection formula
Between the poles Gamma is perfectly finite, and the reflection formula reaches it. For z that is not a whole number, Gamma(z) times Gamma(1 - z) equals pi / sin(pi z). If x is negative, then 1 - x is positive and easy, and one division finishes the job.
The sign comes for free from the sine. Since sin(pi z) changes sign at every whole number, Gamma is negative between -1 and 0, positive between -2 and -1, negative again between -3 and -2, and so on. A routine that works only in logarithms returns the size and loses exactly this sign.
Here is a case you can reproduce. Enter x = -0.5. The page gives Gamma(-0.5) = -3.5449077018110, which is minus two times the square root of pi, and it reports the sign as negative. Its logarithm of the size is 1.2655121234846. If you take the exponential of that logarithm you get +3.5449077, the right size with the wrong sign. That is why the page stores the sign apart from the logarithm.
Underneath, the page uses the Lanczos approximation, which Cornelius Lanczos published in 1964. The version used has g = 7 and nine coefficients, and it typically gives 13 correct decimal places. It switches to the reflection formula when the argument is below one half. A warning on the Lanczos page applies here too: leaving out the smallest coefficients, to save time, gives badly inaccurate answers, because the whole set must be recomputed for a shorter expansion. Nine coefficients are not a convenience that a faster build may trim; they are part of the formula, and the page keeps all of them.
One detail of this page’s own making: the power t^(z + 1/2) in the formula is split into two equal factors. A single power can overflow a double before the decaying exponential that follows has a chance to rescue it.
Why erfc needs its own routine
The error function is defined by an integral of exp(-t^2) from 0 to z, scaled by 2 over the square root of pi. It climbs from -1 to 1 and levels off. The complementary function erfc is defined as 1 - erf, and it measures what is left over, which is the part of the area still in the tail.
A double carries a 53-bit significand, so numbers near 1 are spaced about 1.1e-16 apart. Now take x = 6. The true erfc(6) is 2.1519737e-17, a fifth of that spacing. So erf(6) rounds to exactly 1, and the difference 1 - erf(6) comes out as 0. Every digit is gone. This is the textbook case of catastrophic cancellation, where subtracting two nearby numbers wipes out the information in both.
The page therefore never builds erfc from erf in the tail. From x = 2 upward it uses a continued fraction, first found by Laplace, with 120 terms taken from the tail. The better-known asymptotic series cannot be used, since it diverges for every finite x. Below 2.5 the page sums a series for erf whose terms are all positive, so nothing cancels.
The obvious alternating series does cancel. Summing its first 60 terms in double precision at x = 5 returns about -2.0004, and even a fully converged sum is wrong in the eighth decimal place, giving 0.99999998 where the true value is 0.9999999999985. Same formula, same arithmetic, a different order of operations, and the answer changes completely.
At the entered values the identity card shows the same effect in miniature. For x = 2.5, erfc(2.5) is 0.000406952017444959, while 1 - erf(2.5) gives 0.000406952017445006. They agree to about 12.9 digits. Three of the sixteen digits have already gone.
The inverse works in the other direction. The inverse erf is defined for values strictly between -1 and 1. The page starts from a closed-form guess and then applies six steps of Newton’s method, using erfc near the ends, where 1 - y can be formed exactly. Written through erf, the normal cumulative value is one half of erfc(-x / sqrt 2), and the quantile is the square root of 2 times the inverse erf of 2p - 1. For p = 0.975 that gives 1.959964, the familiar two-sided 95 percent point.
A measured error is not a guaranteed one
The page does not ask you to take its accuracy on faith. It carries a table of 50-digit reference values, built once outside the page, and compares its own routines against them on a fixed grid. The comparison is exact: both the double and the reference are turned into whole numbers, using BigInt arithmetic, before they are subtracted, so the check adds no rounding of its own.
On the build checked, Gamma over 400 points from 0.5 to 148.13 had a worst relative error of 9.25e-14, at the far end, and erf over 700 points reached 1.09e-15. The worst erfc error, 7.4e-14, sits at x = 1.95, just below the point where the routine switches to the continued fraction, which is the cancellation described above at work. These are measurements.
A measurement is a different thing from a guarantee. A grid of a few hundred points samples a curve; it does not prove anything about the gaps between them. A guarantee would need an error bound that holds for every input, and this page does not claim one. Also, engines compute exp, log and pow slightly differently in the last bit, so your browser may report slightly different digits from those quoted here.
Because more than 2,200 reference points means thousands of exact big-number comparisons, the measurement runs in a Web Worker, a background thread, and the page stays responsive while it works.
The method has limits worth stating. It does not handle the incomplete gamma or beta functions, complex arguments, digamma or Bessel functions. Beta is defined here for positive x and y only. Entries are capped at 20 characters and a size of 1,000. Where those limits matter, a specialist library is the right tool, and the measured numbers above tell you how much you can lean on this one.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Gamma function Wikipedia (CC BY-SA)
- Particular values of the gamma function Wikipedia (CC BY-SA)
- Beta function Wikipedia (CC BY-SA)
- Error function Wikipedia (CC BY-SA)
- Lanczos approximation Wikipedia (CC BY-SA)
- Normal distribution Wikipedia (CC BY-SA)
- Catastrophic cancellation Wikipedia (CC BY-SA)
- Machine epsilon Wikipedia (CC BY-SA)
- Double-precision floating-point format Wikipedia (CC BY-SA)
- DLMF: 5.2 Definitions National Institute of Standards and Technology
- DLMF: 5.5 Functional Relations National Institute of Standards and Technology
- DLMF: 7.2 Definitions National Institute of Standards and Technology
- DLMF: 7.9 Continued Fractions National Institute of Standards and Technology
- Number.MAX_VALUE - JavaScript MDN Web Docs (CC BY-SA)
- BigInt - JavaScript MDN Web Docs (CC BY-SA)
- Web Workers API MDN Web Docs (CC BY-SA)