The Verification Venue · a big number, checked three ways before you see it
The Cosine of a Number You Can Type
Ask a browser for the cosine of 10^22 and it answers instantly, but the answer depends on bits of π that no ordinary calculation ever stored: reducing such an argument modulo π/2 is the whole problem, and the double nearest π/2 is shorter than the question by twenty-one orders of magnitude. This page computes π to 522 bits by two independent Machin formulas, agrees them, keeps the common digits, reduces exactly, certifies every digit it prints, and then censuses 10,000,000 random doubles to find where the naive reduction loses its last correct bit, including a live measurement of whatever your own browser's cosine turns out to do.
Type any number below. Three readouts answer at once: your browser's own cosine, the textbook naive reduction followed by a cosine, and the exact value computed from π that this page built itself. Before anything large runs, the page proves its two engines agree on small cases, proves it can catch a deliberately broken engine, and plants a number whose answer is known by construction. Nothing below is recalled; every digit, including π itself, is computed in front of you.
What is evaluated is the double nearest your typing: paste 1e22 if you prefer, and anything up to about 1e57, which is where the 384 stored bits of 2/π stop determining the answer and this page says so instead of printing digits. Every real number reduces to within π/4 of a multiple of π/2, so the reduced argument's own cosine is pinned in advance between 0.70710678… and 1, and cos x is that value or its sine partner, signed by the quadrant. The quadrant is shown beside the answer, and it is the half of the problem the naive method usually loses first.
Your browser, Math.cos(x)
·
measured live, not accused
Naive reduction, then cos
·
r = ·
Exact, certified to 2^-120
·
·
Drag left and watch the exact value lose digits from the right. The counter shows how many of 24 displayed places have settled.
·
computing π …
For an argument near 2^k, the reduced answer is decided by bits k through k+53 of 2/π. The highlighted window is your number's window. Past bit 383 nothing is stored, which is the entire content of the problem.
The census
The page draws 10,000,000 random doubles with exponents from 2^-1 to 2^79 and scores, for each one, how many leading bits the naive method and your browser keep against the exact value. The engine runs the census as 1,000 × 10,000 (chunks × arguments per chunk) across every core you have; a second pass then re-runs the entire census as 640 × 15,625, and the two decompositions must agree cell for cell before the chart is offered as a result.
waiting for the checks to clear
| exponent decade | arguments | naive, mean bits | browser, mean bits |
|---|
Worst case in the sample: ·
The check
Five small batteries run through both engines before anything large is trusted. The wasm column is the compiled engine; the reference column is a deliberately slow, obvious second implementation written from the contract, not from the C.
| battery row | wasm | reference | match |
|---|
The exact path on this page is integer arithmetic from end to end: it never calls a platform transcendental, so the agreement between the two implementations is a property of this page, not of whichever browser opened it. Math.cos and Math.sin appear only as measured quantities, inside the browser column and inside the naive method being measured, and are labelled as such everywhere they are shown.
The byte-for-byte rebuild of engine.c under the pinned clang cannot run in a browser; that check is offline, in research/the-cosine-of-a-number-you-can-type/verify-the-cosine-of-a-number-you-can-type.mjs. What runs here is the digest check against the manifest, the battery, the control, the planted witness, and the full census twice under two chunkings.
What the full-size check does not rule out: two decompositions agreeing rules out a chunk-boundary error and almost nothing else, because both passes could be consistently wrong in the same way. The battery proves the two implementations agree on small instances, not that both are right: they share the argument-stream contract and the record semantics by design. What carries the large-argument result is the interval arithmetic behind the 2^-120 certification and the planted witness.
How the exact path works
π is computed live to 522 bits, twice, by two independent Machin-type identities: 16·arctan(1/5) − 4·arctan(1/239), and 4·arctan(1/2) + 4·arctan(1/3), each evaluated by binary splitting in exact integer arithmetic. The two results are compared bit by bit and only the agreed prefix is kept; the 384-bit tables of 2/π and π/2 that both engines consume are then pinned by bracketing, wide enough to swallow the formulas' own flooring error.
The double nearest π/2 is 0x3ff921fb54442d18: fifty-three bits, twenty-one orders of magnitude shorter than the question 10^22 asks. Reducing exactly needs bits of 2/π far past what any ordinary calculation stores, which is why the tables here are computed, not recalled.
Each census argument is a random double with exponent uniform on [−1, 79], drawn by splitmix64 from the seed 0xc0ffee01. The stream is part of the contract and is implemented three times (C, reference, plan) and cross-checked by the battery. For each argument the engine reduces exactly against the stored tables, evaluates cosine and sine by Taylor series in 128-bit fixed point with every rounding bounded, then applies the quadrant (cos x is cos r, −sin r, −cos r or sin r as n mod 4 runs 0 to 3) and emits the certified signed double plus diagnostic flags, the quadrant among them. Certification bound: 2^-120, and that is an absolute bound. The census path works at a fixed 2^-128 whatever the size of the answer, so an argument close enough to a zero of the cosine could be certified to 2^-120 and still not be the correctly rounded double. Nothing in this census is near that: the closest it comes is a reduced argument of order 2^-23, a hundred bits clear. The typed readout above uses a 192-bit path instead, at roughly 2^-183.
What the census measures, and what it only samples
The browser column is a measurement of your platform and will vary by engine and version. Modern engines perform Payne-Hanek style reduction, so the likely outcome is agreement to within a unit in the last place rather than exactly; that is a finding about your browser, not a disappointment. Nothing here treats your engine's cosine as the truth. Where the exact path is held to an outside standard it is held to integer arithmetic: the two Machin formulas for π, √3/2 and 1/2 at the quadrant witnesses, and the identity cos 2x = 2cos²x − 1, which relates two completely separate reductions of two different numbers and is the one check on this page that the code was not written to satisfy.
The census finds the worst case among its own random sample of 10,000,000 doubles. The true worst case for naive reduction is a searched constant, not a random one; the page exhibits the sampled worst case and says that is what it is.