 Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world.

Tangent Numbers

The first few values are 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 ... (sequence A000182 in OEIS). They are called tangent numbers because they appear as numerators in the Maclaurin series of tan(x).

Important: there are two competing definitions of Tangent numbers in common use (depending on whether you take the even or odd numbered values as non-zero), we use: Which gives: Tangent numbers are used in the computation of Bernoulli numbers, but are also made available here.

Synopsis
#include <boost/math/special_functions/detail/bernoulli.hpp>
template <class T>
T tangent_t2n(const int i);  // Single tangent number (default policy).

template <class T, class Policy>
T tangent_t2n(const int i, const Policy &pol); // Single tangent number (user policy).

// Multiple tangent numbers (default policy).
template <class T, class OutputIterator>
OutputIterator tangent_t2n(const int start_index,
const unsigned number_of_tangent_t2n,
OutputIterator out_it);

// Multiple tangent numbers (user policy).
template <class T, class OutputIterator, class Policy>
OutputIterator tangent_t2n(const int start_index,
const unsigned number_of_tangent_t2n,
OutputIterator out_it,
const Policy& pol);
Examples

We can compute and save a few Tangent numbers.

std::vector<float> tn; // Space for some `float` precision Tangent numbers.

boost::math::tangent_t2n<float>(1, 6, std::back_inserter(tn)); // Fill vector with even Tangent numbers.

for(size_t i = 0; i < tn.size(); i++)
{ // Show vector of even Tangent numbers, showing all significant decimal digits.
std::cout << std::setprecision(std::numeric_limits<float>::digits10)
<< " "
<< tn[i];
}
std::cout << std::endl;

The output is:

1 2 16 272 7936 353792

The source of this example is at bernoulli_example.cpp

Implementation

Tangent numbers are calculated as intermediates in the calculation of the Bernoulli numbers: refer to the Bernoulli numbers documentation for details.

 Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle Walker and Xiaogang Zhang Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)