tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches

Numeric operations on values in ranges. More...

Functions

template<typename Type>
constexpr auto abs (Type input) noexcept -> Type
 Returns the absolute value.
 
template<typename InputIt, typename Type>
constexpr auto accumulate (InputIt first, InputIt last, Type init) noexcept -> Type
 Computes the sum of the given value init and the elements in the range [first, last).
 
template<typename InputIt, typename Type, typename BinaryOperation>
constexpr auto accumulate (InputIt first, InputIt last, Type init, BinaryOperation op) noexcept -> Type
 Computes the sum of the given value init and the elements in the range [first, last).
 
template<etl::builtin_integer Int>
constexpr auto add_sat (Int x, Int y) noexcept -> Int
 
template<typename InputIt, typename OutputIt>
constexpr auto adjacent_difference (InputIt first, InputIt last, OutputIt destination) -> OutputIt
 
template<typename InputIt, typename OutputIt, typename BinaryOperation>
constexpr auto adjacent_difference (InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
 Computes the differences between the second and the first of each adjacent pair of elements of the range [first, last) and writes them to the range beginning at destination + 1. An unmodified copy of *first is written to *destination.
 
template<builtin_integer Int>
constexpr auto div_sat (Int x, Int y) noexcept -> Int
 Computes the saturating division x / y.
 
template<typename M, typename N>
constexpr auto gcd (M m, N n) noexcept -> etl::common_type_t< M, N >
 Computes the greatest common divisor of the integers m and n.
 
template<typename InputIt1, typename InputIt2, typename T>
constexpr auto inner_product (InputIt1 first1, InputIt1 last1, InputIt2 first2, T init) -> T
 Computes inner product (i.e. sum of products) or performs ordered map/reduce operation on the range [first1, last1) and the range beginning at first2.
 
template<typename InputIt1, typename InputIt2, typename T, typename BinaryOperation1, typename BinaryOperation2>
constexpr auto inner_product (InputIt1 first1, InputIt1 last1, InputIt2 first2, T init, BinaryOperation1 op1, BinaryOperation2 op2) -> T
 
template<typename ForwardIt, typename T>
constexpr auto iota (ForwardIt first, ForwardIt last, T value) -> void
 Fills the range [first, last) with sequentially increasing values, starting with value and repetitively evaluating ++value.
 
template<typename M, typename N>
requires (is_integral_v<M> and not is_same_v<M, bool> and is_integral_v<N> and not is_same_v<N, bool>)
constexpr auto lcm (M m, N n) -> common_type_t< M, N >
 Computes the least common multiple of the integers m and n.
 
template<etl::floating_point Float>
constexpr auto midpoint (Float a, Float b) noexcept -> Float
 
template<typename Int>
requires (etl::is_integral_v<Int> and not etl::is_same_v<Int, bool>)
constexpr auto midpoint (Int a, Int b) noexcept -> Int
 Returns half the sum of a + b. If the sum is odd, the result is rounded towards a.
 
template<typename Ptr>
requires etl::is_pointer_v<Ptr>
constexpr auto midpoint (Ptr a, Ptr b) noexcept -> Ptr
 
template<typename InputIt, typename OutputIt>
constexpr auto partial_sum (InputIt first, InputIt last, OutputIt destination) -> OutputIt
 
template<typename InputIt, typename OutputIt, typename BinaryOperation>
constexpr auto partial_sum (InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
 Computes the partial sums of the elements in the subranges of the range [first, last) and writes them to the range beginning at destination. This version uses the given binary function op, both applying etl::move to their operands on the left hand side.
 
template<typename InputIter>
constexpr auto reduce (InputIter first, InputIter last) -> typename etl::iterator_traits< InputIter >::value_type
 Similar to etl::accumulate.
 
template<typename InputIter, typename T>
constexpr auto reduce (InputIter first, InputIter last, T init) -> T
 Similar to etl::accumulate.
 
template<typename InputIter, typename T, typename BinaryOp>
constexpr auto reduce (InputIter first, InputIter last, T init, BinaryOp op) -> T
 Similar to etl::accumulate.
 
template<builtin_integer To, builtin_integer From>
constexpr auto saturate_cast (From x) noexcept -> To
 Converts the value x to a value of type T, clamping x between the minimum and maximum values of type T.
 
template<typename InputIt, typename T, typename BinaryReductionOp, typename UnaryTransformOp>
constexpr auto transform_reduce (InputIt first, InputIt last, T init, BinaryReductionOp reduce, UnaryTransformOp transform) -> T
 https://en.cppreference.com/w/cpp/algorithm/transform_reduce
 
template<typename InputIt1, typename InputIt2, typename T>
constexpr auto transform_reduce (InputIt1 first1, InputIt1 last1, InputIt2 first2, T init) -> T
 https://en.cppreference.com/w/cpp/algorithm/transform_reduce
 
template<typename InputIt1, typename InputIt2, typename T, typename BinaryReductionOp, typename BinaryTransformOp>
constexpr auto transform_reduce (InputIt1 first1, InputIt1 last1, InputIt2 first2, T init, BinaryReductionOp reduce, BinaryTransformOp transform) -> T
 https://en.cppreference.com/w/cpp/algorithm/transform_reduce
 

Detailed Description

Numeric operations on values in ranges.

Function Documentation

◆ abs()

template<typename Type>
auto abs ( Type input) -> Type
nodiscardconstexprnoexcept

Returns the absolute value.

◆ accumulate() [1/2]

template<typename InputIt, typename Type>
auto accumulate ( InputIt first,
InputIt last,
Type init ) -> Type
nodiscardconstexprnoexcept

Computes the sum of the given value init and the elements in the range [first, last).

https://en.cppreference.com/w/cpp/algorithm/accumulate

Examples
numeric.cpp.

◆ accumulate() [2/2]

template<typename InputIt, typename Type, typename BinaryOperation>
auto accumulate ( InputIt first,
InputIt last,
Type init,
BinaryOperation op ) -> Type
nodiscardconstexprnoexcept

Computes the sum of the given value init and the elements in the range [first, last).

https://en.cppreference.com/w/cpp/algorithm/accumulate

◆ add_sat()

template<etl::builtin_integer Int>
auto add_sat ( Int x,
Int y ) -> Int
nodiscardconstexprnoexcept

◆ adjacent_difference() [1/2]

template<typename InputIt, typename OutputIt>
auto adjacent_difference ( InputIt first,
InputIt last,
OutputIt destination ) -> OutputIt
constexpr

◆ adjacent_difference() [2/2]

template<typename InputIt, typename OutputIt, typename BinaryOperation>
auto adjacent_difference ( InputIt first,
InputIt last,
OutputIt destination,
BinaryOperation op ) -> OutputIt
constexpr

Computes the differences between the second and the first of each adjacent pair of elements of the range [first, last) and writes them to the range beginning at destination + 1. An unmodified copy of *first is written to *destination.

◆ div_sat()

template<builtin_integer Int>
auto div_sat ( Int x,
Int y ) -> Int
nodiscardconstexprnoexcept

Computes the saturating division x / y.

◆ gcd()

template<typename M, typename N>
auto gcd ( M m,
N n ) -> etl::common_type_t<M, N>
nodiscardconstexprnoexcept

Computes the greatest common divisor of the integers m and n.

Returns
If both m and n are zero, returns zero. Otherwise, returns the greatest common divisor of |m| and |n|.

◆ inner_product() [1/2]

template<typename InputIt1, typename InputIt2, typename T>
auto inner_product ( InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
T init ) -> T
nodiscardconstexpr

Computes inner product (i.e. sum of products) or performs ordered map/reduce operation on the range [first1, last1) and the range beginning at first2.

◆ inner_product() [2/2]

template<typename InputIt1, typename InputIt2, typename T, typename BinaryOperation1, typename BinaryOperation2>
auto inner_product ( InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
T init,
BinaryOperation1 op1,
BinaryOperation2 op2 ) -> T
nodiscardconstexpr

◆ iota()

template<typename ForwardIt, typename T>
auto iota ( ForwardIt first,
ForwardIt last,
T value ) -> void
constexpr

Fills the range [first, last) with sequentially increasing values, starting with value and repetitively evaluating ++value.

◆ lcm()

template<typename M, typename N>
requires (is_integral_v<M> and not is_same_v<M, bool> and is_integral_v<N> and not is_same_v<N, bool>)
auto lcm ( M m,
N n ) -> common_type_t<M, N>
nodiscardconstexpr

Computes the least common multiple of the integers m and n.

Returns
If either m or n is zero, returns zero. Otherwise, returns the least common multiple of |m| and |n|.

◆ midpoint() [1/3]

template<etl::floating_point Float>
auto midpoint ( Float a,
Float b ) -> Float
constexprnoexcept

◆ midpoint() [2/3]

template<typename Int>
requires (etl::is_integral_v<Int> and not etl::is_same_v<Int, bool>)
auto midpoint ( Int a,
Int b ) -> Int
constexprnoexcept

Returns half the sum of a + b. If the sum is odd, the result is rounded towards a.

CppCon 2019: Marshall Clow "midpoint? How Hard Could it Be?" Integer version was updated to match implementation from libc++.

https://www.youtube.com/watch?v=sBtAGxBh-XI) https://en.cppreference.com/w/cpp/numeric/midpoint

◆ midpoint() [3/3]

template<typename Ptr>
requires etl::is_pointer_v<Ptr>
auto midpoint ( Ptr a,
Ptr b ) -> Ptr
constexprnoexcept

◆ partial_sum() [1/2]

template<typename InputIt, typename OutputIt>
auto partial_sum ( InputIt first,
InputIt last,
OutputIt destination ) -> OutputIt
constexpr

◆ partial_sum() [2/2]

template<typename InputIt, typename OutputIt, typename BinaryOperation>
auto partial_sum ( InputIt first,
InputIt last,
OutputIt destination,
BinaryOperation op ) -> OutputIt
constexpr

Computes the partial sums of the elements in the subranges of the range [first, last) and writes them to the range beginning at destination. This version uses the given binary function op, both applying etl::move to their operands on the left hand side.

BinaryFunction must not invalidate any iterators, including the end iterators, or modify any elements of the range involved.

https://en.cppreference.com/w/cpp/algorithm/partial_sum

Returns
Iterator to the element past the last element written.

◆ reduce() [1/3]

template<typename InputIter>
auto reduce ( InputIter first,
InputIter last ) -> typename etl::iterator_traits<InputIter>::value_type
nodiscardconstexpr

◆ reduce() [2/3]

template<typename InputIter, typename T>
auto reduce ( InputIter first,
InputIter last,
T init ) -> T
nodiscardconstexpr

◆ reduce() [3/3]

template<typename InputIter, typename T, typename BinaryOp>
auto reduce ( InputIter first,
InputIter last,
T init,
BinaryOp op ) -> T
nodiscardconstexpr

◆ saturate_cast()

template<builtin_integer To, builtin_integer From>
auto saturate_cast ( From x) -> To
nodiscardconstexprnoexcept

Converts the value x to a value of type T, clamping x between the minimum and maximum values of type T.

◆ transform_reduce() [1/3]

template<typename InputIt, typename T, typename BinaryReductionOp, typename UnaryTransformOp>
auto transform_reduce ( InputIt first,
InputIt last,
T init,
BinaryReductionOp reduce,
UnaryTransformOp transform ) -> T
nodiscardconstexpr

◆ transform_reduce() [2/3]

template<typename InputIt1, typename InputIt2, typename T>
auto transform_reduce ( InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
T init ) -> T
nodiscardconstexpr

◆ transform_reduce() [3/3]

template<typename InputIt1, typename InputIt2, typename T, typename BinaryReductionOp, typename BinaryTransformOp>
auto transform_reduce ( InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
T init,
BinaryReductionOp reduce,
BinaryTransformOp transform ) -> T
nodiscardconstexpr