E.V.E  0.1-beta

◆ bit_width

eve::bit_width = {}
inlineconstexpr

Callable object computing the bit_width operation.

Required header: #include <eve/function/bit_width.hpp>

Members Functions

Member Effect
operator() the bit_width operation
operator[] Construct a conditional version of current function object

template< unsigned_value T > auto operator()( T x ) const noexcept;

Parameters

x: unsigned value.

Return value

If x is not zero, calculates the number of bits needed to store the value x, that is \(1+\lfloor\log2(x)\rfloor\). If x is zero, returns zero.


auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::bit_width

Parameters

cond : conditional expression

Return value

A Callable object so that the expression bit_width[cond](x, ...) is equivalent to if_else(cond,bit_width(x, ...),x)


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/bit_width.hpp>
#include <eve/constant/inf.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_it pi = {14, 1, 3, 0};
std::cout << "---- simd" << '\n'
<< "<- pi = " << pi << '\n'
<< "-> bit_width(pi) = " << eve::bit_width(pi) << '\n';
std::uint32_t xf = 48;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bit_width(xf) = " << eve::bit_width(xf) << '\n';
return 0;
}
constexpr callable_bit_width_ bit_width
Callable object computing the bit_width operation.
Definition: bit_width.hpp:73
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Wrapper for SIMD registers.
Definition: wide.hpp:65