Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.

Jacobi Elliptic SN, CN and DN

#include <boost/math/special_functions/jacobi_elliptic.hpp>
namespace boost { namespace math {

 template <class T, class U, class V>
 calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn);

 template <class T, class U, class V, class Policy>
 calculated-result-type jacobi_elliptic(T k, U u, V* pcn, V* pdn, const Policy&);

}} // namespaces

The function jacobi_elliptic calculates the three copolar Jacobi elliptic functions sn(u, k), cn(u, k) and dn(u, k). The returned value is sn(u, k), and if provided, *pcn is set to cn(u, k), and *pdn is set to dn(u, k).

The functions are defined as follows, given:

The the angle φ is called the amplitude and:

[Note] Note

φ is called the amplitude.

k is called the modulus.

[Caution] Caution

Rather like other elliptic functions, the Jacobi functions are expressed in a variety of different ways. In particular, the parameter k (the modulus) may also be expressed using a modular angle α, or a parameter m. These are related by:

k = sinα

m = k2 = sin2α

So that the function sn (for example) may be expressed as either:

sn(u, k)

sn(u \ α)

sn(u| m)

To further complicate matters, some texts refer to the complement of the parameter m, or 1 - m, where:

1 - m = 1 - k2 = cos2α

This implementation uses k throughout, and makes this the first argument to the functions: this is for alignment with the elliptic integrals which match the requirements of the Technical Report on C++ Library Extensions. However, you should be extra careful when using these functions!

The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.

The following graphs illustrate how these functions change as k changes: for small k these are sine waves, while as k tends to 1 they become hyperbolic functions:


These functions are computed using only basic arithmetic operations and trigomometric functions, so there isn't much variation in accuracy over differing platforms. Typically errors are trivially small for small angles, and as is typical for cyclic functions, grow as the angle increases. Note that only results for the widest floating point type on the system are given as narrower types have effectively zero error. All values are relative errors in units of epsilon.

Table 3.29. Errors Rates in the Jacobi Elliptic Functions

Significand Size

Platform and Compiler

u < 1

Large u


Win32 / Visual C++ 8.0

Peak=2 Mean=0.5

Peak=44000 Mean=2500


Ubuntu Linux / G++ 4.7

Peak=2.0 Mean=0.5

Peak=25000 Mean=1500


The tests use a mixture of spot test values calculated using the online calculator at, and random test data generated using MPFR at 1000-bit precision and this implementation.


For k > 1 we apply the relations:

Then filter off the special cases:

sn(0, k) = 0 and cn(0, k) = dn(0, k) = 1.

sn(u, 0) = sin(u), cn(u, 0) = cos(u) and dn(u, 0) = 1.

sn(u, 1) = tanh(u), cn(u, 1) = dn(u, 1) = 1 / cosh(u).

And for k4 < ε we have:

Otherwise the values are calculated using the method of arithmetic geometric means.