The guide
Why a big swing is slow and an ellipse has no formula: elliptic integrals, with the convention named
Elliptic integrals turn up in a swinging pendulum and in the length of an ellipse, and they come in three argument conventions that differ by about nine percent.
- 1.85407 K at the parameter m = 0.5
- 1.68575 K at the modulus k = 0.5, a different number
- 2.36825 s exact period of a 1 m pendulum released at 90 degrees
- 15.28 percent how far the small-angle period falls short at 90 degrees
- 25.5270 perimeter of an ellipse with semi-axes 5 and 3
Read the full guide Fold the guide
An ellipse looks gentle. Draw one with semi-axes 5 and 3 and ask how long the curve is, and there is no formula built from the usual functions. The length is 25.5270 in whatever unit the axes use, and the only exact way to say so is with an integral that has a name of its own.
That integral is an elliptic integral. The name comes from the problem that started the family: finding the arc length of an ellipse, studied around 1750 by Giulio Fagnano and Leonhard Euler. The same family turns up somewhere that has nothing to do with ellipses, the swing of a pendulum. Both uses come down to two numbers called K and E, and getting them right depends on one habit: saying which convention the input is written in.
Where the integrals come from
The incomplete integral of the first kind, in Legendre’s trigonometric form, adds up 1 divided by the square root of 1 minus m times the sine squared, as the angle runs from 0 up to a limit phi. The second kind adds up the square root itself. Stop at a quarter turn and you have the complete integrals K and E. The NIST library defines the complete ones in exactly that way, as the incomplete ones at phi equal to a right angle.
Take the ellipse with semi-axes a and b, a the larger. Its eccentricity is the square root of 1 minus b squared over a squared, and one quarter of the perimeter, measured in units of a, is the complete integral of the second kind at that eccentricity. So the perimeter is 4 a E. In the parameter convention the argument is the eccentricity squared. For the 5 by 3 ellipse that is 1 minus 9 over 25, which is 0.64, and 4 times 5 times E(0.64) is the 25.5270 above.
One number, three spellings
Three equivalent ways to write the argument are in use. There is the modular angle alpha. There is the modulus k, the sine of alpha. And there is the parameter m, which is k squared. Each determines the other two, so they can be swapped freely, but a book or a program picks one and does not always say which. The reference page on these integrals warns that reputable references and software packages use different conventions, so one must be careful with the notation, and it notes that a widely used package takes the parameter where many textbooks take the modulus.
The slip is expensive. K at the modulus 0.5 is 1.68575. K at the parameter 0.5 is 1.85407. Both get written K(0.5), and the smaller is about nine percent below the larger. A modulus of 0.5 is a parameter of 0.25, and a parameter of 0.5 is a modulus of about 0.7071, which is an angle of 45 degrees. The page shows all three for every entry and writes the convention beside every result.
Why the arithmetic-geometric mean is fast
To compute K without summing a slow series, start with two numbers: 1 and the square root of 1 minus m. Replace them by their arithmetic mean and their geometric mean, and repeat. The two sequences squeeze together to a common limit, the arithmetic-geometric mean, and K is pi divided by twice that limit. Lagrange wrote the first algorithm built on this pair of sequences, and Gauss analysed its properties further.
For m = 0.5 the first pair is 1 and 0.70711. After one step it is 0.85355 and 0.84090. After two, 0.84722490 and 0.84720127. After three the two agree to nine decimal places, and after four they are equal to the last digit a double can hold, 0.84721308. Then K is pi over twice that, which is 1.85407. Four steps, for fifteen digits.
The speed is not luck. A relation in the NIST library shows that each small correction term equals the square of the previous one divided by four times the new arithmetic mean, so the gap collapses quadratically and the number of correct digits roughly doubles with every step. Even a parameter one trillionth short of 1 needs about seven steps, although K itself is then only about 15.2: it creeps upward, never settling, as m nears 1.
E comes from the same steps: the small correction terms are added up with powers of two as weights. The page checks the result a second way with Legendre’s relation, E times K-prime plus E-prime times K minus K times K-prime, which must equal pi over 2. Legendre introduced it in 1811 for the complete integrals, and here K-prime and E-prime are K and E at the complementary parameter 1 minus m. Across seven values of m the two sides agree to within about 2e-15.
Why a large swing is slow
A pendulum of length L in gravity g, released from rest at an angle, obeys an equation in which the acceleration is minus g over L times the sine of the angle. Replace the sine by the angle itself, as the small-angle approximation does, and the swing takes 2 pi times the square root of L over g, however high it starts. That is the textbook formula, and it is only right for small swings.
With the true sine there is no solution in elementary functions, but the period is exactly an elliptic integral: four times the square root of L over g, times K, with the parameter equal to the sine squared of half the release angle. The NIST library puts it as four quarter periods, and it names the angle of 180 degrees as the separatrix between swinging and going over the top. Release from 180 degrees and the pendulum balances upside down for ever, which is why the page refuses that angle.
Take L = 1 m and g = 9.80665 m/s squared. The small-angle period is 2.00641 s. Released from 90 degrees, the parameter is 0.5, K is 1.85407, and the exact period is 2.36825 s: 1.18034 times longer, which is exactly 2K over pi. The small-angle value falls short by 15.28 percent. At 10 degrees the shortfall is only 0.19 percent, which is why the approximation survives in classrooms.
The page does not simply trust the formula. It also steps the equation of motion forward with an embedded Runge-Kutta pair of orders five and four, finds the second time the speed passes through zero, and compares. At 90 degrees the two periods agree to about 6e-14 s.
Near 180 degrees that check turns touchy. The pendulum lingers close to the unstable top, where tiny errors grow fast. At 179.99 degrees, with L equal to g, two runs of the integration at different tolerances differ by about 6.5e-5 in time. The exact formula is untouched by this, so the page shows the spread of the two runs and tells you to trust the elliptic value there.
The ellipse and its approximations
Because the exact perimeter needs E, people use approximations, and Ramanujan gave two close ones. For the 5 by 3 ellipse the first gives 25.526986 against the exact 25.526999, a relative miss of about 5e-7. The second gives 25.52699886, a relative miss of about 2.4e-11. A published error analysis shows that the second always falls short of the true perimeter, by an amount that grows with the fifth power of h, the squared ratio of the axis difference to the axis sum.
The simplest rule is pi times a plus b, the circle on the mean radius. For 5 by 3 it gives 25.1327, which is 1.54 percent short. For a flat 10 by 1 ellipse it gives 34.5575 against an exact 40.6397, which is 14.97 percent short. A perimeter quoted without saying which formula produced it cannot be trusted at the second digit. The page prints the exact value from E, a direct integral, and all three approximations side by side, each labelled as approximate, with the percentage by which it misses.
The incomplete integrals and the direct perimeter have no arithmetic-geometric shortcut here, so the page integrates them numerically. It uses adaptive Gauss-Kronrod quadrature: the same sample points serve a 15-point rule and a 7-point rule inside it, and the difference between the two estimates the error, which the page shows. For F at 60 degrees with m = 0.5 it returns 1.14243 with an estimated error near 3e-17, and E at 60 degrees comes to 0.96495.
Two details matter when m is close to 1. The page carries the distance 1 minus m separately and works it out exactly from the typed digits, because in floating point 1 minus 0.999999 is 1.00000000003e-6 rather than 1e-6, and that shifts K by about a part in 1e12. And near the sharp peak of the integrand, the quadrature measures the angle from 90 degrees, since rounding the angle itself would cost digits.
What the page cannot do
It does not cover the Jacobi elliptic functions, which are defined through the inverses of elliptic integrals, nor elliptic curves, the integral of the third kind or Carlson forms. Negative parameters are outside it. K has no value at m = 1, where it diverges, while E equals 1 there.
It is the ideal pendulum, a point mass on a light rod with no friction, and a release angle of 180 degrees is refused. Numbers are doubles, good to about 14 digits: the worst relative error measured for E against an independent 80-digit reference was about 7e-15, close to m = 1. The quadrature error is a cautious estimate and not a proof. The heavy parts run in a background worker, the kind of thread the Web Workers documentation describes, so typing never freezes the page, and numbers are printed with the platform’s number formatter.
Work through it once. Set m = 0.5, release the pendulum at 90 degrees, then switch the first box to the modulus and watch the nine percent appear.
Sources
Every source consulted for this guide. Links checked November 11, 2026.
- Elliptic integral Wikipedia (CC BY-SA 4.0)
- Arithmetic-geometric mean Wikipedia (CC BY-SA 4.0)
- Pendulum (mechanics) Wikipedia (CC BY-SA 4.0)
- Ellipse Wikipedia (CC BY-SA 4.0)
- Legendre's relation Wikipedia (CC BY-SA 4.0)
- Gauss-Kronrod quadrature formula Wikipedia (CC BY-SA 4.0)
- Runge-Kutta methods Wikipedia (CC BY-SA 4.0)
- Small-angle approximation Wikipedia (CC BY-SA 4.0)
- Jacobi elliptic functions Wikipedia (CC BY-SA 4.0)
- DLMF 19.2 Definitions NIST Digital Library of Mathematical Functions
- DLMF 19.7 Connection Formulas NIST Digital Library of Mathematical Functions
- DLMF 19.8 Quadratic Transformations NIST Digital Library of Mathematical Functions
- DLMF 22.19 Physical Applications NIST Digital Library of Mathematical Functions
- Ramanujan's Perimeter of an Ellipse arXiv (listing math/0506384)
- Web Workers API MDN Web Docs (CC BY-SA)
- Intl.NumberFormat MDN Web Docs (CC BY-SA)