ForHosting KIT · Math

Quadratic equation solver

Type a, b and c and get both roots with the discriminant: x² − 3x + 2 = 0 has a discriminant of 1 and the roots 2 and 1. Complex pairs appear when the discriminant is negative, each root shown to six decimals. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Coefficient A
1
Coefficient B
-3
Coefficient C
2
You get
Discriminant
1
Type of roots
two_real

roots free in your browser

How the formula finds the roots

Every quadratic equation can be written as a times x squared, plus b times x, plus c, equal to zero. The solver first computes the discriminant, b squared minus four times a times c, using exact whole-number arithmetic. It then applies the classic formula: minus b, plus or minus the square root of the discriminant, all divided by two times a. Take x² − 3x + 2 = 0. Here a is 1, b is −3 and c is 2, so the discriminant is 9 minus 8, which is 1. Its square root is 1, and the two roots are 4 divided by 2 and 2 divided by 2, that is 2 and 1.

Reading the result and avoiding common slips

When the discriminant is negative there is no real solution, and the two roots are shown as a real part and an imaginary part that mirror each other, a conjugate pair. The most common slip by hand is the sign of b: in x² − 3x + 2, b is −3, not 3, and the formula starts with minus b. Another is forgetting that two times a sits under the whole numerator. Coefficients must be whole numbers no larger than one million in absolute value, and the first one cannot be zero. Each root is rounded to six decimal places, with halves moved away from zero. Equations of higher degree are not handled here.

Half-up roots without Math.sqrt noise

Real roots use the classic formula x equals negative b plus or minus the square root of D, all over two a. The square root is obtained from an integer isqrt of n times S squared, where S is one million, then rounded half-up to six decimal places. Division uses a symmetric half-up rule that moves halves away from zero.

Complex roots use the same scaled path on the absolute value of D so the imaginary parts stay conjugate even when a is negative. Because every step is integer, two independent oracles that follow the signed rules produce identical strings on every vector.

Order of roots and practical limits

x1 is always the plus branch and x2 is always the minus branch of the quadratic formula. For complex solutions the imaginary part of x1 carries the sign that falls out of dividing the scaled square root by two a, and x2 flips that imaginary sign. Outputs never call the network, never read the system clock and never depend on locale.

Version one deliberately skips non-integer coefficients, symbolic factoring and higher-degree polynomials so the contract stays short and auditable.

Homework checks

Verify textbook roots of monic and non-monic quadratics.

Teaching complex numbers

Show conjugate pairs when the discriminant is negative.

Pipeline tests

Pin exact six-decimal strings in continuous integration.

Engineering models

Solve simple characteristic equations with integer coefficients.

Are decimals allowed?

Not in v1. Coefficients must be integers or integer strings.

Does it use floating Math.sqrt?

No. The oracle is integer isqrt plus scaled half-up.

What does the discriminant tell me?

The discriminant is b squared minus four times a times c. If it is positive there are two different real roots, if it is zero there is one repeated root, and if it is negative the roots form a complex conjugate pair.

Which root is x1 and which is x2?

The first root always uses the plus sign before the square root in the formula and the second uses the minus sign. For x² − 3x + 2 = 0 that gives 2 first and 1 second.

What happens if a is zero?

The equation is refused, because without the squared term it is no longer quadratic but linear. The first coefficient must be a whole number other than zero.

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.

POSThttps://api.kit.forhosting.com/dev/quadratic-equation

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.

curl -X POST https://api.kit.forhosting.com/dev/quadratic-equation \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":1,"b":-3,"c":2}'
{
  "a": 1,
  "b": -3,
  "c": 2
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.quadratic_equation",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs_coeff1000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Enter integer coefficients a, b and c for the equation ax² + bx + c = 0 and get the discriminant, the nature of the roots, and both solutions as real or complex pairs.

Integer coefficients only in version one

Absolute values above one million are also rejected so the integer path stays bounded. This solver accepts a, b and c as JSON integers or as canonical integer strings with an optional leading minus sign. Floats, booleans, decimal points, a leading plus sign and padded zeros such as 01 are rejected with a typed invalid_input error on the offending field. The leading coefficient a must not be zero; that case is reported as a_zero because the equation would no longer be quadratic.

Exact discriminant and three natures

You always receive two root objects x1 and x2, each with a real part re and an imaginary part im formatted as strings with exactly six decimal places. That fixed shape makes it easy to render results in tables, widgets and automated pipelines without special cases for missing fields. The discriminant D equals b squared minus four a c and is computed with exact integer arithmetic, never with IEEE floating point. When D is positive the nature is two_real, when D is zero the nature is repeated, and when D is negative the nature is complex.

Can a be zero?

No. a_zero is returned because the equation would be linear.

How precise are the roots?

Always six decimal places with half-up rounding.

What is nature?

two_real, repeated or complex from the sign of D.

Is it free in the browser?

Yes. The widget runs locally; API uses $0.002.

Read the full KIT documentation →