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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Engel Expansion

#include <boost/math/tools/engel_expansion.hpp>
namespace boost::math::tools {

template<typename Real, typename Z = int64_t>
class engel_expansion {
    engel_expansion(Real x);

    std::vector<Z> const & digits() const;

    template<typename T, typename Z_>
    friend std::ostream& operator<<(std::ostream& out, engel_expansion<T, Z>& engel);

The engel_expansion class provided by Boost converts a floating point number into an Engel series.

Here's a minimal working example:

using boost::math::constants::e;
using boost::math::tools::engel_expansion;
auto engel = engel_expansion(e<double>());
std::cout << "e ≈ " << engel << "\n";
// Prints:
// e ≈ {1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}

The digits of an Engel expansion tend to grow exponentially, so the integer template option might need to be utilized. For example, we can use a wider integer type via

using boost::multiprecision::checked_int1024_t;
auto engel = engel_expansion<__float128, checked_int1024_t>(pi<__float128>());