/*************************************************************************** * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and * * Martin Renou * * Copyright (c) QuantStack * * * * Distributed under the terms of the BSD 3-Clause License. * * * * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ #ifndef XSIMD_FP_MANIPULATION_HPP #define XSIMD_FP_MANIPULATION_HPP #include "xsimd_numerical_constant.hpp" namespace xsimd { template batch ldexp(const batch& x, const batch, N>& e); template batch frexp(const batch& arg, batch, N>& exp); /******************************************************** * Floating point manipulation functions implementation * ********************************************************/ /* origin: boost/simd/arch/common/simd/function/ldexp.hpp */ /* * ==================================================== * copyright 2016 NumScale SAS * * Distributed under the Boost Software License, Version 1.0. * (See copy at http://boost.org/LICENSE_1_0.txt) * ==================================================== */ template inline batch ldexp(const batch& x, const batch, N>& e) { using btype = batch; using itype = as_integer_t; itype ik = e + maxexponent(); ik = ik << nmb(); return x * bitwise_cast(ik); } /* origin: boost/simd/arch/common/simd/function/ifrexp.hpp */ /* * ==================================================== * copyright 2016 NumScale SAS * * Distributed under the Boost Software License, Version 1.0. * (See copy at http://boost.org/LICENSE_1_0.txt) * ==================================================== */ template inline batch frexp(const batch& arg, batch, N>& exp) { using b_type = batch; using i_type = batch, N>; i_type m1f = mask1frexp(); i_type r1 = m1f & bitwise_cast(arg); b_type x = arg & bitwise_cast(~m1f); exp = (r1 >> nmb()) - maxexponentm1(); exp = select(bool_cast(arg != b_type(0.)), exp, zero()); return select((arg != b_type(0.)), x | bitwise_cast(mask2frexp()), b_type(0.)); } } #endif