fpprec:100$ /* Compute the circumference of an ellipse with semi-axes a and b with a relative accuracy of fpprec decimal digits. Code is adapted from Carlson (1995), eqs 2.36 - 2.39. */ C(a,b) := block( [x : bfloat(max(a, b)), y : bfloat(min(a, b)), s : 0, m : 1, tol : 0.1b0^fpprec], if y < tol * x then return( 4 * x ), tol:sqrt(tol), while x - y > tol * y do block( [t : (x + y) / 2], y : sqrt(x * y), x : t, m : 2 * m, s : s + m * (x - y)^2 ), return( bfloat(%pi) * ((a + b)^2 - s) / (x + y) ) )$