Boost logo

Boost Users :

Subject: Re: [Boost-users] generalize boost macros
From: Gero Peterhoff (gero.peterhoff_at_[hidden])
Date: 2019-02-02 20:12:16


Am 02.02.19 um 19:15 schrieb John Maddock via Boost-users:
>
>> This is not constexpr for float128_t and the compiler generates a
>> function call. :-(
>
> This works fine for me:
>
>
> #include <boost/cstdfloat.hpp>
> #include <boost/math/constants/constants.hpp>
>
> int main()
> {
>    using boost::float128_t;
>
>    constexpr float128_t pi = boost::math::constants::pi<float128_t>();
>
>    return 0;
> }
>
That's exactly my problem.

namespace std
{
// declare missing log2, cannot say constexpr: compilererror
inline float128_t log2(const float128_t& arg) noexcept
{
 return log2q(arg);
}
}

// also not constexpr
inline float128_t myfunc(const float128_t& arg) noexcept
{
 // log2_e not available
 // constexpr float128_t factor =
boost::math::constants::log2_e<float128_t>();

 // compiler generates a function call to log2
 const float128_t factor =
std::log2(boost::math::constants::e<float128_t>());

 return arg*factor;
}

thx
Gero




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net