◆ frexp()

std::pair<IEEEValue, IEEEValue> boost::simd::frexp ( IEEEValue const &  x)

This function object returns a mantissa and an exponent pair for the input.

Header <boost/simd/function/frexp.hpp>
Semantic:

For every parameter of floating type

std::tie(m, e)= frexp(x);

is similar to:

auto e = tofloat(exponent(x)+1);
auto m = mantissa(x)/2;
Notes:
  • Without the pedantic_ decorator, calling frexp on Nan or Inf has undefined behavior.
  • the exponent and matissa are both returned as floating values: if you need integral type exponent (as in the standard library) use ifrexp
  • This function splits a floating point value \(x\) in a signed mantissa \(m\) and an exponent \(e\) so that: \(x = m\times 2^e\), with absolute value of \(m \in [0.5, 1[\) (except for \(x = 0\))

    Warning
    Take care that these results differ from the returns of the functions mantissa and exponent
Decorators
  • pedantic_ slower, but special values as Nan or Inf are handled properly.
  • std_ transmits the call to std::frexp and converts the exponent.
See also
ifrexp, exponent, mantissa
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 pm, pe;
std::tie(pm, pe) = bs::frexp(pf);
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> std::tie(pm, pe) = bs::frexp(pf) = " << '\n'
<< "-> pm = " << pm << '\n'
<< "-> pie = " << pe<< '\n' ;
float xf = 2.0f;
float m, e;
std::tie(m, e) = bs::frexp(xf);
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< "-> std::tie(m, e) = bs::frexp(xf) = " << '\n'
<< "-> m = " << m << '\n'
<< "-> e = " << e << '\n' ;
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
-> std::tie(pm, pe) = bs::frexp(pf) =
-> pm = (0.5, 0.5, -0.5, 0.5)
-> pie = (1, 2, 1, 0)
---- scalar
xf = 2
-> std::tie(m, e) = bs::frexp(xf) =
-> m = 0.5
-> e = 2