◆ convert
Callable object converting a value to another type. Required header: Members Functions
template<value T, scalar_value Target>
auto operator()( T const& x, as_<Target> const& t) const noexcept;
Parameters
Return value For a value auto r = convert(x, as_<Target>{});
constexpr callable_convert_ convert Callable object converting a value to another type. Definition: convert.hpp:87 is semantically equivalent to: Target r;
{
r = static_cast<Target>(x);
}
else if constexpr( simd_value<T> )
{
for(std::size_t i=;i<x.size();++i)
r[i] = static_cast<Target>(x[i]);
}
Supported decorators
ExampleSee it live on Compiler Explorer #include <eve/function/convert.hpp>
#include <eve/function/saturated/convert.hpp>
#include <eve/function/converter.hpp>
#include <eve/constant/valmax.hpp>
#include <eve/wide.hpp>
#include <iostream>
using wide_ft = eve::wide<float, eve::fixed<4>>;
using wide_it = eve::wide<std::int64_t, eve::fixed<4>>;
using int_16 = eve::as<std::int16_t>;
using int_64 = eve::as<std::int64_t>;
int main()
{
wide_ft pf = {-1.0f, 2.3f, 45000.7f, -64768.6f};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
double xf = -64768.4f;
std::int64_t xi = -64768;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- xi = " << xi << '\n'
return 0;
}
constexpr callable_valmax_ valmax Callable object computing the greatest representable value. Definition: valmax.hpp:53 constexpr saturated_type const saturated Higher-order Callable Object imbuing saturation semantic onto other Callable Objects. Definition: saturated.hpp:68 |