◆ bitwise_cast()

template<typename Target >
Target boost::simd::bitwise_cast ( Value const &  x)

This function object function implementing bitwise_cast capabilities.

Performs a bit-preserving cast of its parameters into an arbitrary type Target.

Precondition
sizeof(Value) == sizeof(Target)
Header <boost/simd/function/bitwise_cast.hpp>
Example:
#include <boost/simd/bitwise.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack<float, 4>;
using iT = std::int32_t;
using pack_it = bs::pack<iT, 4>;
int main() {
pack_ft pf = {1.0f, 2.0f, -1.0f, 0.5f};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::bitwise_cast<pack_it>(pf) = "
<< bs::bitwise_cast<pack_it>(pf) << '\n';
float xf = 2.0f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::bitwise_cast<iT>(xf) = " << bs::bitwise_cast<iT>(xf)
<< '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
-> bs::bitwise_cast<pack_it>(pf) = (1065353216, 1073741824, -1082130432, 1056964608)
---- scalar
<- xf = 2
-> bs::bitwise_cast<iT>(xf) = 1073741824
Parameters
xValue to cast
Returns
A value of type Target which is bit-equivalent to x.