## ◆ ldexp()

 Value0 boost::simd::ldexp ( Value0 const & x, Value1 const & n )

This function object returns $$x$$ multiplied by by $$2^{n}$$.

Note

If n is not of integral type it is truncated: ldexp(x,n) is similar to: x*pow(2, trunc(n))

Precondition
The cardinal_of and the size of elements value of the types of x and n must be identical
Decorators
• pedantic_ By default ldexp does not take care of denormal or limiting values. Use the pedantic_ decorator if these are to be properly computed.
Example:
#include <boost/simd/ieee.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = {1.0f, 2.0f, -1.0f, 0.5f};
pack_ft qf = {1.0f, 2.0f, -1.0f, 3.0f};
pack_it qi = {1, 2, -1, 3};
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "-> bs::ldexp(pf, qf) = " << bs::ldexp(pf, qf) << '\n'
<< "<- qi = " << qi << '\n'
<< "-> bs::ldexp(pf, qi) = " << bs::ldexp(pf, qi) << '\n';
float xf = 2.0f, yf = 3.0;
std::int32_t yi = 3;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "-> bs::ldexp(xf, yf) = " << bs::ldexp(xf, yf) << '\n'
<< "<- yi = " << yi << '\n'
<< "-> bs::ldexp(xf, yi) = " << bs::ldexp(xf, yi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
<- qf = (1, 2, -1, 3)
-> bs::ldexp(pf, qf) = (2, 8, -0.5, 4)
<- qi = (1, 2, -1, 3)
-> bs::ldexp(pf, qi) = (2, 8, -0.5, 4)
---- scalar
<- xf = 2
<- yf = 3
-> bs::ldexp(xf, yf) = 16
<- yi = 3
-> bs::ldexp(xf, yi) = 16