EllAlgo 1.6.13
Loading...
Searching...
No Matches
Functions
algo Namespace Reference

Functions

template<typename N >
auto half_nonnegative (N n) noexcept -> typename std::enable_if_t< std::is_integral< N >::value, N >
 Compute half of a non-negative integral number.
 

Function Documentation

◆ half_nonnegative()

template<typename N >
auto algo::half_nonnegative ( N  n) -> typename std::enable_if_t<std::is_integral<N>::value, N>
noexcept

Compute half of a non-negative integral number.

This function computes half of a non-negative integral number. For integral types, it uses unsigned arithmetic to avoid overflow when dealing with negative numbers.

\[ \lfloor n/2 \rfloor \]

Template Parameters
NThe integral type
Parameters
[in]nThe non-negative number to halve
Returns
Half of the input number

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

\[ \lfloor n/2 \rfloor \]