E.V.E
v2022.09.01

◆ roundscale

eve::roundscale = {}
inlineconstexpr

Computes the scaled input rounding.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T, int scale >
T roundscale(T x, int scale) noexcept;
}
constexpr callable_roundscale_ roundscale
Computes the scaled input rounding.
Definition: roundscale.hpp:115
Definition: all_of.hpp:22

Parameters

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

Return value

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

Example

#include <eve/module/core.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_i_ i
Callable object computing the pure imaginary ( ) value.
Definition: i.hpp:51
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

Semantic Modifiers

  • Masked Call

    The call eve;roundscale[mask](x, scale) provides a masked version of eve::roundscale which is equivalent to if_else (mask, roundscale(x, scale), x).

    Example

    #include <eve/module/core.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[ignore_first(2)](pf, 4) = " << eve::roundscale[eve::ignore_first(2)](pf, 4) << '\n';
    return 0;
    }
    Conditional expression ignoring the k first lanes from a eve::simd_value.
    Definition: conditional.hpp:419
    • eve::to_nearest, eve::toward_zero, eve::upward, eve::downward

      If d is one of these 4 decorators The call d(roundscale)(x), call is equivalent to eve::ldexp(d(eve::round)(eve::ldexp(a0,scale), -scale))

      #include <eve/module/core.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';
      << " -> upward(roundscale)(pf, 4) = " << eve::downward(eve::roundscale)(pf, 4) << '\n'
      << " -> downward(roundscale)(pf, 4) = " << eve::upward(eve::roundscale)(pf, 4) << '\n'
      << " -> to_nearest(roundscale)(pf, 4) = " << eve::to_nearest(eve::roundscale)(pf, 4) << '\n';
      return 0;
      }
      constexpr upward_type const upward
      Higher-order Callable Object imbuing upward rounding semantic onto other Callable Objects.
      Definition: roundings.hpp:160
      constexpr downward_type const downward
      Higher-order Callable Object imbuing rounding downard semantic onto other Callable Objects.
      Definition: roundings.hpp:161
      constexpr to_nearest_type const to_nearest
      Higher-order Callable Object imbuing rounding to nearest semantic onto other Callable Objects.
      Definition: roundings.hpp:162