# Modulo Calculator

> Divides one number by another and reports the remainder under the three common sign conventions (truncated as in C/JavaScript, floored as in Python, and the non-negative Euclidean modulo) together with the integer quotient.

- Calculator id: `modulo` · Category: Math (`math`) · Tool name: `calculate_modulo`
- Canonical page: https://tttkmbb.com/math/modulo · This document: https://tttkmbb.com/math/modulo.md · JSON definition: https://tttkmbb.com/math/modulo.json

## Purpose

Divides one number by another and reports the remainder under the three common sign conventions (truncated as in C/JavaScript, floored as in Python, and the non-negative Euclidean modulo) together with the integer quotient.

**Use when:** You need a mod b, the remainder of a division, or want to know how different programming languages treat negative operands.

**Do not use when:** You need the prime factors or divisors of a number (use prime-factorization) or a change of number base (use base-converter).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `dividend` | number |  | required | The number being divided. Integers are exact; decimals are allowed. (min -1000000000000000, max 1000000000000000) |
| `divisor` | number |  | required | The number to divide by; must not be 0. (min -1000000000000000, max 1000000000000000) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `remainder` | number |  | a − b × trunc(a / b): the % operator of C, Java and JavaScript. |
| `quotient` | number |  | trunc(a / b), rounded toward zero. |
| `floored_modulo` | number |  | a − b × ⌊a / b⌋: the % operator of Python and the mod of spreadsheets. |
| `modulo` | number |  | The mathematical residue in [0, \|b\|): a − \|b\| × ⌊a / \|b\|⌋. |
| `is_divisible` | boolean |  | true when the remainder is 0. |
| `expression` | string |  | a = b × quotient + remainder with the truncated convention. |

## Formula

`truncated: r = a − b·trunc(a/b); floored: r = a − b·⌊a/b⌋; Euclidean: r = a − |b|·⌊a/|b|⌋ (0 ≤ r < |b|)`

## Data Sources

- Wikipedia – Modulo — https://en.wikipedia.org/wiki/Modulo (reference, retrieved 2026-09-23)
- Wikipedia – Euclidean division — https://en.wikipedia.org/wiki/Euclidean_division (reference, retrieved 2026-09-23)
- Wolfram MathWorld – Mod — https://mathworld.wolfram.com/Mod.html (reference, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/modulo?dividend=…&divisor=…`
- `POST https://tttkmbb.com/api/v1/calculate/modulo` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/modulo · OpenAPI operationId `calculate_modulo` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "modulo", "inputs": {…}}`

## Example

- 17 mod 5: inputs `{"dividend":17,"divisor":5}` → `{"remainder":2,"quotient":3,"floored_modulo":2,"modulo":2,"is_divisible":false,"expression":"17 = 5 × 3 + 2"}`
- −7 mod 3: inputs `{"dividend":-7,"divisor":3}` → `{"remainder":-1,"quotient":-2,"floored_modulo":2,"modulo":2,"is_divisible":false}`

```
GET https://tttkmbb.com/api/v1/calculate/modulo?dividend=17&divisor=5
```

## Limitations

You need the prime factors or divisors of a number (use prime-factorization) or a change of number base (use base-converter). All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Why does −7 mod 3 give both −1 and 2?**

Languages disagree on the sign: C, Java and JavaScript return −1 (remainder takes the sign of the dividend), Python and Excel return 2 (sign of the divisor). The Euclidean modulo is always non-negative.

**Does it work with decimals?**

Yes, e.g. 7.5 mod 2 = 1.5. Because inputs are binary floating-point numbers, results like 0.3 mod 0.1 may show tiny rounding artefacts.

## Related

- [GCD and LCM Calculator](https://tttkmbb.com/math/gcd-lcm.md) — The Euclidean algorithm is built from repeated modulo.
- [Number Base Converter](https://tttkmbb.com/math/base-converter.md) — Base conversion uses repeated division with remainder.
- [Day of the Week Calculator](https://tttkmbb.com/everyday/day-of-week.md) — Calendar arithmetic is modulo 7.
