TTS v4.1.0
The Tiny Test System
Loading...
Searching...
No Matches
tts::between< T, U > Struct Template Reference

Generates values linearly spaced between two bounds. More...

Detailed Description

template<typename T, typename U = T>
struct tts::between< T, U >

Generates values linearly spaced between two bounds.

The element at index i of a sequence of size N is first + i*step, where step = (last-first)/(N-1), both computed in the target type, so rounding makes the gaps slightly unequal. If rounding carries a value past the last bound, the last bound is returned instead. A sequence of size 1 and a scalar target get the first bound.

Template Parameters
TType of the first bound
UType of the last bound

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <array>
TTS_CASE_WITH("Test tts::between generator",
(std::array<float, 10>, int, double),
tts::between {-4, 4})
<typename T>(T const& args)
{
if constexpr(std::is_arithmetic_v<T>)
{
TTS_EQUAL(args, static_cast<T>(-4));
}
else
{
using value_type = typename T::value_type;
for(std::size_t i = 0; i < args.size(); ++i)
{
TTS_ULP_EQUAL(args[ i ],
static_cast<value_type>(-4 + static_cast<value_type>(i) * value_type {8} /
static_cast<value_type>((args.size() - 1))),
4);
}
}
};