E.V.E  0.1-beta

◆ roundscale

eve::roundscale = {}
inlineconstexpr

Callable object computing the scaled rouding.

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

Members Functions

Member Effect
operator() the computation of the scaled rouding
operator[] Construct a conditional version of current function object

auto operator()(floating_value auto x, int scale) const noexcept;
Definition: value.hpp:83

Parameters

x: floating real value.

scale : int or std::integral_constant of int type limited to the range [0, 15].

Return value

Returns the elementwise rounding of the scaled input. The number of fraction bits retained is specified by scale. By default the internal rounding after scaling is done to nearest integer. The call is equivalent to ldexp(round(ldexp(a0,scale),-scale))


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

Example

See it live on Compiler Explorer

#include <eve/function/roundscale.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wide_ft pf( [](auto i, auto) { return 1.2345678+i; } );
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> roundscale(pf, 4) = " << eve::roundscale(pf, 4) << '\n';
float xf = 0x1.fffffep0f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << std::hexfloat << xf << '\n';
for (int i = 0; i < 16; ++i)
std::cout << "-> toward_zero(roundscale)(xf," << std::setw(2) << i << ") = " << std::hexfloat << eve::toward_zero(eve::roundscale)(xf, i) << '\n';
return 0;
}
constexpr callable_roundscale_ roundscale
Callable object computing the scaled rouding.
Definition: roundscale.hpp:100
constexpr toward_zero_type const toward_zero
Higher-order Callable Object imbuing rounding toward zero semantic onto other Callable Objects.
Definition: roundings.hpp:163
Wrapper for SIMD registers.
Definition: wide.hpp:65