Gamma function calculator
Γ(2.5) is 1.3293403882: the gamma function extends the factorial to every real number, so Γ(5) equals 4!, which is 24. Enter any real value except zero and the negative whole numbers and get about fifteen significant digits. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- X
- 2.5
- Gamma
- 1.3293403882
Evaluates the gamma function Γ(x), the continuous extension of the factorial, for any real number x. Uses the Lanczos approximation with the reflection formula for negative non-integer inputs, delivering about fifteen significant digits of accuracy. Non-positive integers, where gamma has poles, are rejected with a clear error. Free, deterministic, and private in your browser — no account and no network call required, since the whole computation runs on-device under the parse engine.
A factorial that also works between whole numbers
The factorial only makes sense for whole numbers: 4! is 4 × 3 × 2 × 1. The gamma function fills in the gaps. For every positive whole number n, Γ(n) equals (n−1)!, so Γ(5) is 24, but the curve also passes smoothly through every value in between, such as Γ(2.5) = 1.3293403882, and even through Γ(0.5), which equals the square root of π. Away from the whole numbers it is defined by an integral with no closed form, which is why a calculator is needed. Statistics depends on it: the beta, gamma and chi-square distributions use it so that their probabilities add up to one.
How the value is worked out, and the usual slips
Instead of evaluating the integral, the calculator uses the Lanczos approximation, a short formula built on nine fixed coefficients that gives about fifteen significant digits. For values below 0.5 it first applies Euler's reflection formula, which turns the question into one about 1 − x, where the formula behaves well. The result is rounded to ten decimal places. The most common mistake is the shift by one: Γ(n) is the factorial of n − 1, not of n. The second is expecting a value at zero or at a negative whole number, where none exists. And very large inputs run out of room: Γ(172) is already close to the largest number ordinary arithmetic can hold, so bigger values are reported as out of range.
How the Lanczos approximation computes Γ(x)
The gamma function generalizes the factorial: for positive integers, Γ(n) equals (n−1)!, and for everything else it is defined by an integral that has no closed form. For x < 0.5 the algorithm applies Euler's reflection formula, Γ(x) = π / (sin(πx) · Γ(1−x)), which moves the argument into the well-conditioned right half-plane before applying the same series. Everything is a fixed sequence of double-precision arithmetic: no iteration to a tolerance, no randomness, no date, no network.
What you can do with it
Statistics and probability
Evaluate normalizing constants for beta, gamma, and chi-square distributions without installing SciPy.
Homework and teaching
Verify Γ(n) = (n−1)!, half-integer values like Γ(2.5), and the reflection formula with reproducible answers.
FAQ
How accurate is the result?
The Lanczos approximation with nine coefficients is accurate to roughly fifteen significant digits; output is rounded to ten decimal places for a stable contract.
How is the gamma function related to the factorial?
For a positive whole number n, Γ(n) equals (n−1)!, the factorial of the number before it. So Γ(5) is 4!, which is 24. Between the whole numbers the curve continues smoothly, giving values such as Γ(2.5).
Why is gamma undefined at zero and the negative integers?
Because the function has poles there: its value shoots off to infinity. The calculator rejects 0, −1, −2 and so on with a clear message instead of showing a meaningless infinity.
Can I take the gamma of a negative number like −0.5?
Yes, as long as it is not a whole number. For values below 0.5 the calculator uses Euler's reflection formula, which links Γ(x) to Γ(1−x); Γ(−0.5), for example, equals −2√π.
What is the gamma function used for?
It appears wherever factorials meet continuous quantities: the normalizing constants of the beta, gamma and chi-square distributions in statistics, the volume of a sphere in n dimensions, and fractional calculus.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/gamma-function \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x":2.5}'const res = await fetch("https://api.kit.forhosting.com/math/gamma-function", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x": 2.5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/gamma-function",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x": 2.5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/gamma-function", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x":2.5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x":2.5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/gamma-function", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x": 2.5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.gamma_function",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
How the Lanczos approximation computes Γ(x)
The standard practical way to evaluate it numerically is the Lanczos approximation, which replaces the integral with a short rational expansion of nine fixed coefficients around g = 7. For x ≥ 0.5 the series is evaluated directly: a partial sum is combined with a power and an exponential term, and the result is accurate to roughly fifteen significant digits — close to the limit of IEEE-754 double precision. The only true failures of the definition are the poles at zero and the negative integers, where sin(πx) vanishes; the pure function detects those inputs up front and raises invalid_input with a stable English message instead of returning Infinity or NaN.
Inputs, outputs, and the rounding contract
Very large positive arguments overflow double precision (Γ(172) is already near the limit), and in that case the function reports an explicit out-of-range error rather than silently returning Infinity. Error messages use stable substrings such as finite real number and non-positive integers so automated tests can match them across releases. The input is a single required field, x, a finite real number; the aliases value and z are also accepted so form fields and scripts can bind naturally. Missing, non-numeric, infinite, or NaN values raise invalid_input with a message that names the field, and so do non-positive integers, which are poles of the function. The success payload echoes x and returns gamma, the computed value.
Use cases, edge cases, and integration notes
The gamma function appears wherever factorials meet continuous quantities: the beta and chi-square distributions in statistics, the volume of an n-dimensional sphere in geometry, fractional calculus, and combinatorial identities like Γ(0.5) = √π. A statistics student can verify that Γ(5) = 24, confirm the half-integer values such as Γ(2.5) = 1.3293403882, and explore negative non-integers like Γ(−0.5) = −2√π without installing SciPy or a computer-algebra system. Tier A means the calculation itself runs entirely on-device with the parse engine — only the platform wrapper involves the network, and the price of $0.002 per item applies to the API path. Automation pipelines that need millions of evaluations should still call the API modestly, since each call is metered as one item, but the deterministic contract means results can be safely cached by the caller.
Integration use cases
Geometry and research scripts
Compute volumes of n-dimensional spheres and fractional-calculus factors from a deterministic API.
Technical questions
Is this free?
Yes. Tier A runs entirely in your browser without an account; the metered API path costs $0.002 per item.
What happens at zero or negative integers?
Gamma has poles there, so the function returns invalid_input with a clear message instead of Infinity.
Does it call the network?
No. The parse engine keeps the calculation on-device; the same pure function runs in the browser and on the API.
Who authored this capability?
hedy, on the ForHosting KIT workshop.