E.V.E
v2022.09.01

◆ convert

eve::convert = {}
inlineconstexpr

Converts a value to another type.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template<value T, scalar_value Target>
Target convert( T x, as_<Target> t) noexcept
}
constexpr callable_convert_ convert
Converts a value to another type.
Definition: convert.hpp:67
Definition: all_of.hpp:22

Parameters

Return value

  • Elementwise conversion of x in the Target type is returned.
Note
  • Conversion operated by eve::convert follows the regular rules of C++ type conversion, including the cases leading to Undefined Behaviors.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
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};
wide_it pi = {-1, 2, -3, eve::valmax(eve::as<std::int64_t>())};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> convert(pf, int_64()_) = " << eve::convert(pf, int_64()) << '\n'
<< "-> convert(pf, int_16()) = = " << eve::convert(pf, int_16()) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> convert(pi, as(eve::as<double>())) = " << eve::convert(pi, eve::as<double>()) << '\n';
double xf = -64768.4f;
std::int64_t xi = -64768;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> convert(xf, int_64()) = " << eve::convert(xf, int_64()) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> convert(xi, eve::as<double>()) = " << eve::convert(xi, eve::as<double>()) << '\n';
return 0;
}
constexpr callable_valmax_ valmax
Computes the the greatest representable value.
Definition: valmax.hpp:55
constexpr callable_pi_ pi
Callable object computing the constant .
Definition: pi.hpp:49
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • eve::saturated

    The expression saturated(convert)(x,t) computes a saturated conversion of x to the type wrapped by t.

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    using int_16 = eve::as<std::int16_t>;
    int main()
    {
    wide_ft pf = {-1.0f, 2.3f, 45000.7f, -64768.6f};
    std::cout << "---- simd" << '\n'
    << "<- pf = " << pf << '\n'
    << "-> convert(pf, int_16()_) = " << eve::convert(pf, int_16()) << '\n'
    << "-> saturated(convert)(pf, int_16()) = " << eve::saturated(eve::convert)(pf, int_16()) << '\n';
    return 0;
    }
    constexpr saturated_type const saturated
    Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
    Definition: saturated.hpp:68