Complex number calculator
The complex number calculator performs the four basic arithmetic operations on two complex numbers given as real and imaginary parts.
Run — free
You supply a = a_real + a_imag·i and b = b_real + b_imag·i, choose add, subtract, multiply or divide, and receive the resulting complex number in both rectangular form and a readable display string. Division is computed with the exact conjugate formula and correctly rejects division by zero. The same deterministic code runs free in your browser and through the paid API, so what you test on this page is exactly what your integration receives.
What a complex number operation actually computes
A complex number is a pair of real numbers written as a + bi, where i is the imaginary unit satisfying i² = −1. Addition and subtraction work component by component: the real parts combine and the imaginary parts combine independently, so (3 + 2i) + (1 − 4i) = 4 − 2i. Multiplication is the interesting case because it uses the defining property of i. Expanding (a + bi)(c + di) with the distributive law gives ac + adi + bci + bdi², and since i² = −1 the result is (ac − bd) + (ad + bc)i. The real part of a product is not the product of the real parts, which is the single most common mistake people make by hand. This complex number calculator applies these closed-form formulas directly, with no iteration and no approximation beyond the final rounding, so the answer is deterministic: the same inputs always produce byte-identical outputs, whether the computation happens in your browser tab or on our edge servers through the API.
Division and the conjugate trick
Dividing complex numbers is the operation that most often needs a calculator, because the formula is not obvious. To compute (a + bi) / (c + di) you multiply numerator and denominator by the conjugate of the denominator, (c − di). The denominator then becomes c² + d², a plain real number, and the numerator expands with the multiplication rule. The final result is ((ac + bd) / (c² + d²)) + ((bc − ad) / (c² + d²))i. The one case where this breaks down is when c² + d² = 0, which happens only when c and d are both zero — the zero complex number. Division by zero is undefined in the complex field just as it is for real numbers, and this endpoint reports it as an invalid input error instead of returning an infinite or NaN result that would silently corrupt a downstream pipeline. Results are rounded to ten decimal places so that floating-point noise never appears in the output, and a negative zero is normalized to zero for clean, comparable responses.
Where complex arithmetic shows up in practice
Complex numbers are not an academic curiosity; they are the working notation of several engineering disciplines. Electrical engineers represent impedances and phasors as complex numbers, so combining two circuit elements in series is an addition and computing transfer functions is a division. Signal processing expresses frequency components as complex values from a Fourier transform, and filtering multiplies them by complex coefficients. Control theory places poles and zeros on the complex plane, and quantum mechanics is written in complex amplitudes from the ground up. In all of these fields the arithmetic itself is mechanical — the four operations on this page cover it completely — and the value of an API is that it can be embedded in a validation step, a teaching tool or a code generator without reimplementing the formulas. Because the capability is stateless and deterministic, it is safe to cache, safe to retry and safe to run in parallel across as many pairs of operands as your workload requires.
What you can do with it
Check circuit impedance math
Add or divide complex impedances when combining components in series and parallel, and verify the hand calculation before committing a board design.
Build a teaching or homework tool
Feed student exercises through the API to generate exact worked answers for (a + bi) × (c + di) without maintaining the formulas yourself.
Validate signal processing output
Cross-check a DSP pipeline by comparing its complex products and quotients against an independent, deterministic reference implementation.
FAQ
What does it cost?
$0.002 per request via the API. It is also free to run in your browser on this page — the same code executes both ways.
Which operations are supported?
Add, subtract, multiply and divide, passed in the operation field. Each takes two complex numbers given as real and imaginary parts.
What happens when I divide by zero?
If the second complex number is 0 + 0i, the request is rejected with an invalid input error. Division by the zero complex number is undefined and is never approximated.
How precise is the result?
The formulas are exact closed forms; the output is rounded to ten decimal places to remove floating-point noise, and negative zero is normalized to zero.
Can I enter negative or decimal parts?
Yes. Real and imaginary parts accept any finite number, including negatives and decimals such as 2.5 or −0.75.
Is anything stored?
No. The computation is stateless: the four numbers are processed in memory and discarded, and only the result is returned.
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/complex-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a_real":3,"a_imag":2,"b_real":1,"b_imag":-4,"operation":"multiply"}'const res = await fetch("https://api.kit.forhosting.com/math/complex-number", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a_real": 3,
"a_imag": 2,
"b_real": 1,
"b_imag": -4,
"operation": "multiply"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/complex-number",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a_real": 3,
"a_imag": 2,
"b_real": 1,
"b_imag": -4,
"operation": "multiply"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/complex-number", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a_real":3,"a_imag":2,"b_real":1,"b_imag":-4,"operation":"multiply"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a_real":3,"a_imag":2,"b_real":1,"b_imag":-4,"operation":"multiply"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/complex-number", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a_real": 3,
"a_imag": 2,
"b_real": 1,
"b_imag": -4,
"operation": "multiply"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.complex_number",
"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. |